c90-array-lval-1.c, [...]: New tests.

* gcc.dg/c90-array-lval-1.c, gcc.dg/c90-scope-1.c,
	gcc.dg/c99-array-lval-1.c, gcc.dg/c99-const-expr-1.c,
	gcc.dg/c99-func-1.c, gcc.dg/c99-func-2.c, gcc.dg/c99-scope-1.c:
	New tests.

From-SVN: r35602
This commit is contained in:
Joseph Myers 2000-08-10 09:19:44 +01:00 committed by Joseph Myers
parent da40cbf67a
commit 9052d3bebc
8 changed files with 157 additions and 0 deletions

View file

@ -1,3 +1,10 @@
2000-08-09 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/c90-array-lval-1.c, gcc.dg/c90-scope-1.c,
gcc.dg/c99-array-lval-1.c, gcc.dg/c99-const-expr-1.c,
gcc.dg/c99-func-1.c, gcc.dg/c99-func-2.c, gcc.dg/c99-scope-1.c:
New tests.
2000-08-09 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.abi/ptrflags.C: Adjust rtti member names.

View file

@ -0,0 +1,21 @@
/* Test for non-lvalue arrays decaying to pointers: in C99 only. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
struct s { char c[1]; };
extern struct s foo (void);
void
bar (void)
{
char *t;
(foo ()).c[0]; /* { dg-bogus "warning" "warning in place of error" } */
t = (foo ()).c; /* { dg-bogus "warning" "warning in place of error" } */
(foo ()).c + 1; /* { dg-bogus "warning" "warning in place of error" } */
}
/* { dg-error "non-lvalue" "array not decaying to lvalue" { target *-*-* } 14 }
{ dg-error "non-lvalue" "array not decaying to lvalue" { target *-*-* } 15 }
{ dg-error "non-lvalue" "array not decaying to lvalue" { target *-*-* } 16 }
*/

View file

@ -0,0 +1,34 @@
/* Test for new block scopes in C99. Inspired by C99 Rationale (N897). */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do run } */
/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
struct foo {
char a;
};
extern void abort (void);
extern void exit (int);
int
sfoo (void)
{
if (sizeof (struct foo { int a; double b; char *c; void *d; }))
(void) 0;
return sizeof (struct foo);
}
int
main (void)
{
int t, u;
t = sfoo ();
u = sizeof (struct foo);
/* With C90 scoping rules the new declaration of struct foo is in scope
above; with C99 it is local to the if.
*/
if (t == u)
abort (); /* C99 rules apply. */
else
exit (0); /* C90 rules apply. */
}

View file

@ -0,0 +1,17 @@
/* Test for non-lvalue arrays decaying to pointers: in C99 only. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
struct s { char c[1]; };
extern struct s foo (void);
void
bar (void)
{
char *t;
(foo ()).c[0]; /* { dg-bogus "non-lvalue" "array not decaying to lvalue" { xfail *-*-* } } */
t = (foo ()).c; /* { dg-bogus "non-lvalue" "array not decaying to lvalue" { xfail *-*-* } } */
(foo ()).c + 1; /* { dg-bogus "non-lvalue" "array not decaying to lvalue" { xfail *-*-* } } */
}

View file

@ -0,0 +1,16 @@
/* Test for constraints on constant expressions. In C90 it is clear that
certain constructs are not permitted in unevaluated parts of an
expression (except in sizeof); in C99 it might fall within implementation
latitude; and if the operands are suitable, diagnostics should not be
issued.
*/
/* Origin: Joseph Myers <jsm28@cam.ac.uk>; inspired by
http://deja.com/getdoc.xp?AN=524271595&fmt=text by Peter Seebach.
*/
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
/* The comma operator is in a subexpression that is not evaluated, so OK
by C99. In C90 a diagnostic is required since it is not in a sizeof.
*/
int i = (1 ? 0 : (2, 3));

View file

@ -0,0 +1,17 @@
/* Test for C99 __func__. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do run } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
extern void abort (void);
extern int strcmp (const char *, const char *);
extern void exit (int);
int
main (void)
{
if (strcmp (__func__, "main") || sizeof (__func__) != 5)
abort ();
else
exit (0);
}

View file

@ -0,0 +1,11 @@
/* Test for C99 __func__: not a string constant. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
void
foo (void)
{
__func__ "foo"; /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "parse error" "__func__ not string constant" { xfail *-*-* } 9 } */
}

View file

@ -0,0 +1,34 @@
/* Test for new block scopes in C99. Inspired by C99 Rationale (N897). */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do run { xfail *-*-* } } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
struct foo {
char a;
};
extern void abort (void);
extern void exit (int);
int
sfoo (void)
{
if (sizeof (struct foo { int a; double b; char *c; void *d; }))
(void) 0;
return sizeof (struct foo);
}
int
main (void)
{
int t, u;
t = sfoo ();
u = sizeof (struct foo);
/* With C90 scoping rules the new declaration of struct foo is in scope
above; with C99 it is local to the if.
*/
if (t == u)
exit (0); /* C99 rules apply. */
else
abort (); /* C90 rules apply. */
}