diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-08-10 08:19:44 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-08-10 08:19:44 +0000 |
commit | 24f5c60b03c4b79ca7d6cf68657066c2566e8c04 (patch) | |
tree | d0cd0063959a5d0dc1fe4a1a374d8ccbb93bffcd /gcc/testsuite | |
parent | 12629520b693e2ca20788783c11b8894a5bb6576 (diff) | |
download | gcc-24f5c60b03c4b79ca7d6cf68657066c2566e8c04.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@35602 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c90-array-lval-1.c | 21 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c90-scope-1.c | 34 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-array-lval-1.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-const-expr-1.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-func-1.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-func-2.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-scope-1.c | 34 |
8 files changed, 157 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 92686a8ca08..15b748e2968 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. diff --git a/gcc/testsuite/gcc.dg/c90-array-lval-1.c b/gcc/testsuite/gcc.dg/c90-array-lval-1.c new file mode 100644 index 00000000000..900dd844ea8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c90-array-lval-1.c @@ -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 } +*/ diff --git a/gcc/testsuite/gcc.dg/c90-scope-1.c b/gcc/testsuite/gcc.dg/c90-scope-1.c new file mode 100644 index 00000000000..ad36b7063fb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c90-scope-1.c @@ -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. */ +} diff --git a/gcc/testsuite/gcc.dg/c99-array-lval-1.c b/gcc/testsuite/gcc.dg/c99-array-lval-1.c new file mode 100644 index 00000000000..831fb54ca0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-array-lval-1.c @@ -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 *-*-* } } */ +} diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-1.c b/gcc/testsuite/gcc.dg/c99-const-expr-1.c new file mode 100644 index 00000000000..c3082ee38f7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-const-expr-1.c @@ -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)); diff --git a/gcc/testsuite/gcc.dg/c99-func-1.c b/gcc/testsuite/gcc.dg/c99-func-1.c new file mode 100644 index 00000000000..43fb0321774 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-func-1.c @@ -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); +} diff --git a/gcc/testsuite/gcc.dg/c99-func-2.c b/gcc/testsuite/gcc.dg/c99-func-2.c new file mode 100644 index 00000000000..11737d6ce45 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-func-2.c @@ -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 } */ +} diff --git a/gcc/testsuite/gcc.dg/c99-scope-1.c b/gcc/testsuite/gcc.dg/c99-scope-1.c new file mode 100644 index 00000000000..256b39c115a --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-scope-1.c @@ -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. */ +} |