c99-flex-array-5.c, [...]: New tests.
authorJoseph Myers <joseph@codesourcery.com>
Sun, 14 Nov 2004 23:24:14 +0000 (23:24 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 14 Nov 2004 23:24:14 +0000 (23:24 +0000)
* gcc.dg/c99-flex-array-5.c, gcc.dg/c99-fordecl-3.c,
gcc.dg/comp-goto-1.c, gcc.dg/comp-goto-2.c, gcc.dg/comp-goto-3.c,
gcc.dg/format/strfmon-2.c, gcc.dg/pointer-arith-1.c,
gcc.dg/pointer-arith-2.c, gcc.dg/pointer-arith-3.c,
gcc.dg/pointer-arith-4.c, gcc.dg/switch-5.c, gcc.dg/switch-6.c,
gcc.dg/switch-7.c: New tests.

From-SVN: r90637

14 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c99-flex-array-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c99-fordecl-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/comp-goto-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/comp-goto-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/comp-goto-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/format/strfmon-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-arith-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-arith-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-arith-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-arith-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/switch-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/switch-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/switch-7.c [new file with mode: 0644]

index b01b06a2cf0320a28591f3e69db87833eda4c895..c21b4e1ec1469ec2c24bc47132a25df8dd7c1d58 100644 (file)
@@ -1,3 +1,12 @@
+2004-11-14  Joseph S. Myers  <joseph@codesourcery.com>
+
+       * gcc.dg/c99-flex-array-5.c, gcc.dg/c99-fordecl-3.c,
+       gcc.dg/comp-goto-1.c, gcc.dg/comp-goto-2.c, gcc.dg/comp-goto-3.c,
+       gcc.dg/format/strfmon-2.c, gcc.dg/pointer-arith-1.c,
+       gcc.dg/pointer-arith-2.c, gcc.dg/pointer-arith-3.c,
+       gcc.dg/pointer-arith-4.c, gcc.dg/switch-5.c, gcc.dg/switch-6.c,
+       gcc.dg/switch-7.c: New tests.
+
 2004-11-14  Dorit Naishlos  <dorit@il.ibm.com>
 
        * gcc.dg/vect/vect-78.c: Now vectorized on powerpc*.
diff --git a/gcc/testsuite/gcc.dg/c99-flex-array-5.c b/gcc/testsuite/gcc.dg/c99-flex-array-5.c
new file mode 100644 (file)
index 0000000..11c8d1c
--- /dev/null
@@ -0,0 +1,6 @@
+/* Test for flexible array members: not permitted in unions.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+union u { int a; char b[]; }; /* { dg-error "error: flexible array member in union" } */
diff --git a/gcc/testsuite/gcc.dg/c99-fordecl-3.c b/gcc/testsuite/gcc.dg/c99-fordecl-3.c
new file mode 100644 (file)
index 0000000..c51a555
--- /dev/null
@@ -0,0 +1,15 @@
+/* Test for C99 declarations in for loops.  Test constraints: struct
+   and union tags can't be declared there (affirmed in response to
+   DR#277).  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+void
+foo (void)
+{
+  for (struct s { int p; } *p = 0; ;) /* { dg-error "error: 'struct s' declared in 'for' loop initial declaration" } */
+    ;
+  for (union u { int p; } *p = 0; ;) /* { dg-error "error: 'union u' declared in 'for' loop initial declaration" } */
+    ;
+}
diff --git a/gcc/testsuite/gcc.dg/comp-goto-1.c b/gcc/testsuite/gcc.dg/comp-goto-1.c
new file mode 100644 (file)
index 0000000..66afac8
--- /dev/null
@@ -0,0 +1,13 @@
+/* Test diagnostics for addresses of labels and computed gotos.  Test
+   with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (void)
+{
+  void *p = &&a;
+  goto *p;
+ a: ;
+}
diff --git a/gcc/testsuite/gcc.dg/comp-goto-2.c b/gcc/testsuite/gcc.dg/comp-goto-2.c
new file mode 100644 (file)
index 0000000..babfe9b
--- /dev/null
@@ -0,0 +1,13 @@
+/* Test diagnostics for addresses of labels and computed gotos.  Test
+   with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+void
+f (void)
+{
+  void *p = &&a; /* { dg-warning "warning: taking the address of a label is non-standard" } */
+  goto *p; /* { dg-warning "warning: ISO C forbids 'goto \\*expr;'" } */
+ a: ;
+}
diff --git a/gcc/testsuite/gcc.dg/comp-goto-3.c b/gcc/testsuite/gcc.dg/comp-goto-3.c
new file mode 100644 (file)
index 0000000..add1861
--- /dev/null
@@ -0,0 +1,13 @@
+/* Test diagnostics for addresses of labels and computed gotos.  Test
+   with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+void
+f (void)
+{
+  void *p = &&a; /* { dg-error "error: taking the address of a label is non-standard" } */
+  goto *p; /* { dg-error "error: ISO C forbids 'goto \\*expr;'" } */
+ a: ;
+}
diff --git a/gcc/testsuite/gcc.dg/format/strfmon-2.c b/gcc/testsuite/gcc.dg/format/strfmon-2.c
new file mode 100644 (file)
index 0000000..1ecef71
--- /dev/null
@@ -0,0 +1,13 @@
+/* Test for strfmon format checking.  Test for missing fill character
+   at end of format.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#include "format.h"
+
+void
+foo (char *s, size_t m)
+{
+  strfmon (s, m, "%="); /* { dg-warning "missing fill character at end" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-1.c b/gcc/testsuite/gcc.dg/pointer-arith-1.c
new file mode 100644 (file)
index 0000000..fec2054
--- /dev/null
@@ -0,0 +1,39 @@
+/* Test diagnostics for arithmetic on void and function pointers.
+   Test with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void *p;
+void (*f)(void);
+
+void
+g (void)
+{
+  p + 0;
+  p + 1;
+  0 + p;
+  1 + p;
+  p - 0;
+  p - 1;
+  p += 0;
+  p += 1;
+  p -= 0;
+  p -= 1;
+  f + 0;
+  f + 1;
+  0 + f;
+  1 + f;
+  f - 0;
+  f - 1;
+  f += 0;
+  f += 1;
+  f -= 0;
+  f -= 1;
+  p[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  p - p;
+  f - f;
+}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-2.c b/gcc/testsuite/gcc.dg/pointer-arith-2.c
new file mode 100644 (file)
index 0000000..8e95ab5
--- /dev/null
@@ -0,0 +1,41 @@
+/* Test diagnostics for arithmetic on void and function pointers.
+   Test with -Wpointer-arith.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wpointer-arith" } */
+
+void *p;
+void (*f)(void);
+
+void
+g (void)
+{
+  p + 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p + 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  0 + p; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  1 + p; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p - 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p - 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p += 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p += 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p -= 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p -= 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  f + 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f + 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  0 + f; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  1 + f; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f - 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f - 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f += 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f += 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f -= 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f -= 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  p[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
+  0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
+  f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  p - p; /* { dg-warning "warning: pointer of type 'void \\*' used in subtraction" } */
+  f - f; /* { dg-warning "warning: pointer to a function used in subtraction" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-3.c b/gcc/testsuite/gcc.dg/pointer-arith-3.c
new file mode 100644 (file)
index 0000000..90f5241
--- /dev/null
@@ -0,0 +1,41 @@
+/* Test diagnostics for arithmetic on void and function pointers.
+   Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+void *p;
+void (*f)(void);
+
+void
+g (void)
+{
+  p + 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p + 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  0 + p; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  1 + p; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p - 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p - 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p += 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p += 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p -= 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  p -= 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
+  f + 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f + 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  0 + f; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  1 + f; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f - 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f - 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f += 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f += 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f -= 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  f -= 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
+  p[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
+  0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
+  f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  p - p; /* { dg-warning "warning: pointer of type 'void \\*' used in subtraction" } */
+  f - f; /* { dg-warning "warning: pointer to a function used in subtraction" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-4.c b/gcc/testsuite/gcc.dg/pointer-arith-4.c
new file mode 100644 (file)
index 0000000..3e577fc
--- /dev/null
@@ -0,0 +1,41 @@
+/* Test diagnostics for arithmetic on void and function pointers.
+   Test with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+void *p;
+void (*f)(void);
+
+void
+g (void)
+{
+  p + 0; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p + 1; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  0 + p; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  1 + p; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p - 0; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p - 1; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p += 0; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p += 1; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p -= 0; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  p -= 1; /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" } */
+  f + 0; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f + 1; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  0 + f; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  1 + f; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f - 0; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f - 1; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f += 0; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f += 1; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f -= 0; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  f -= 1; /* { dg-error "error: pointer to a function used in arithmetic" } */
+  p[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
+  0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
+  /* { dg-error "error: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
+  f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+  p - p; /* { dg-error "error: pointer of type 'void \\*' used in subtraction" } */
+  f - f; /* { dg-error "error: pointer to a function used in subtraction" } */
+}
diff --git a/gcc/testsuite/gcc.dg/switch-5.c b/gcc/testsuite/gcc.dg/switch-5.c
new file mode 100644 (file)
index 0000000..7c1c3d4
--- /dev/null
@@ -0,0 +1,75 @@
+/* Test diagnostics for switch statements and labels therein.  Test
+   with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (int a, double d, void *p)
+{
+  switch (d) /* { dg-error "error: switch quantity not an integer" } */
+    {
+    }
+  switch (p) /* { dg-error "error: switch quantity not an integer" } */
+    {
+    }
+  switch (a)
+    {
+    case (void *)0: ; /* { dg-error "error: pointers are not permitted as case values" } */
+    }
+  switch (a)
+    {
+    case (double)0: ; /* { dg-error "error: case label does not reduce to an integer constant" } */
+    }
+  switch (a)
+    {
+    case (char)0: ;
+    }
+  switch (a)
+    {
+    case 0 ... 0: ;
+    }
+  switch (a)
+    {
+    case 0 ... -1: ; /* { dg-warning "warning: empty range specified" } */
+    }
+  switch (a)
+    {
+    case 0 ... -2: ; /* { dg-warning "warning: empty range specified" } */
+    }
+  switch (a)
+    {
+    case 0:
+    default: /* { dg-error "error: this is the first default label" } */
+    case 1:
+    default: ; /* { dg-error "error: multiple default labels in one switch" } */
+    }
+  switch (a)
+    {
+    case 0: /* { dg-error "error: previously used here" } */
+    case 1:
+    case 0: ; /* { dg-error "error: duplicate case value" } */
+    }
+ case 1: ; /* { dg-error "error: case label not within a switch statement" } */
+ default: ; /* { dg-error "error: 'default' label not within a switch statement" } */
+   break; /* { dg-error "error: break statement not within loop or switch" } */
+   continue; /* { dg-error "error: continue statement not within a loop" } */
+   switch (a)
+     {
+     case a: ; /* { dg-error "error: case label does not reduce to an integer constant" } */
+     }
+   switch (a)
+     {
+     case 0: /* { dg-error "error: this is the first entry overlapping that value" } */
+     case -1 ... 1: /* { dg-error "error: duplicate \\(or overlapping\\) case value" } */
+     case 2 ... 3: /* { dg-error "error: previously used here" } */
+     case 2: /* { dg-error "error: duplicate case value" } */
+     case 4 ... 7: /* { dg-error "error: this is the first entry overlapping that value" } */
+     case 6 ... 9: ; /* { dg-error "error: duplicate \\(or overlapping\\) case value" } */
+     }
+   switch (a)
+     {
+     case 0:
+       continue; /* { dg-error "error: continue statement not within a loop" } */
+     }
+}
diff --git a/gcc/testsuite/gcc.dg/switch-6.c b/gcc/testsuite/gcc.dg/switch-6.c
new file mode 100644 (file)
index 0000000..70cc188
--- /dev/null
@@ -0,0 +1,14 @@
+/* Test diagnostics for switch statements and labels therein.  Test
+   for case ranges with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+void
+f (int a)
+{
+  switch (a)
+    {
+    case 0 ... 0: ; /* { dg-warning "warning: range expressions in switch statements are non-standard" } */
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/switch-7.c b/gcc/testsuite/gcc.dg/switch-7.c
new file mode 100644 (file)
index 0000000..d3fdfb4
--- /dev/null
@@ -0,0 +1,14 @@
+/* Test diagnostics for switch statements and labels therein.  Test
+   for case ranges with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+void
+f (int a)
+{
+  switch (a)
+    {
+    case 0 ... 0: ; /* { dg-error "error: range expressions in switch statements are non-standard" } */
+    }
+}