More C standards testcases

Joseph S. Myers jsm28@cam.ac.uk
Wed Aug 9 14:07:00 GMT 2000


Here are some more C standards testcases.  OK to commit?

The XFAILs will get separate PRs sent.  At present c90-array-lval-1.c
and c99-array-lval-1.c get spurious FAILs and XPASSes because they
trigger the tree-checking ICE reported in PR c/351.  This is a
regression from some time in the past two or three months (failing as of
the date of that PR, but working not long before then).

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.

diff -ruN dg.old/c90-array-lval-1.c gcc.dg/c90-array-lval-1.c
--- dg.old/c90-array-lval-1.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c90-array-lval-1.c	Wed Aug  9 19:43:51 2000
@@ -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 -ruN dg.old/c90-scope-1.c gcc.dg/c90-scope-1.c
--- dg.old/c90-scope-1.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c90-scope-1.c	Wed Aug  9 19:43:51 2000
@@ -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 -ruN dg.old/c99-array-lval-1.c gcc.dg/c99-array-lval-1.c
--- dg.old/c99-array-lval-1.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c99-array-lval-1.c	Wed Aug  9 19:43:51 2000
@@ -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 -ruN dg.old/c99-const-expr-1.c gcc.dg/c99-const-expr-1.c
--- dg.old/c99-const-expr-1.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c99-const-expr-1.c	Wed Aug  9 19:43:51 2000
@@ -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 -ruN dg.old/c99-func-1.c gcc.dg/c99-func-1.c
--- dg.old/c99-func-1.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c99-func-1.c	Wed Aug  9 19:43:51 2000
@@ -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 -ruN dg.old/c99-func-2.c gcc.dg/c99-func-2.c
--- dg.old/c99-func-2.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c99-func-2.c	Wed Aug  9 19:43:51 2000
@@ -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 -ruN dg.old/c99-scope-1.c gcc.dg/c99-scope-1.c
--- dg.old/c99-scope-1.c	Thu Jan  1 00:00:00 1970
+++ gcc.dg/c99-scope-1.c	Wed Aug  9 19:43:51 2000
@@ -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.  */
+}

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc-patches mailing list