This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

More C tests, batch 2


Here is a second batch of tests for messages from or related to the C
parser.  Many more subsequent tests will be needed to get adequate
coverage of other messages not exercised in the current testsuite.

These tests pass on mainline.  Applied to mainline.  The diagnostic
location in func-outside-*.c is bad; I'll file a PR for that.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-11-06  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc.dg/anon-struct-6.c, gcc.dg/anon-struct-7.c,
	gcc.dg/anon-struct-8.c, gcc.dg/bitfld-10.c, gcc.dg/bitfld-11.c,
	gcc.dg/bitfld-12.c, gcc.dg/func-outside-1.c,
	gcc.dg/func-outside-2.c, gcc.dg/label-decl-1.c,
	gcc.dg/label-decl-2.c, gcc.dg/label-decl-3.c,
	gcc.dg/label-decl-4.c, gcc.dg/struct-empty-1.c,
	gcc.dg/struct-empty-2.c, gcc.dg/struct-empty-3.c,
	gcc.dg/struct-semi-1.c, gcc.dg/struct-semi-2.c,
	gcc.dg/struct-semi-3.c: New tests.

diff -rupN GCC.orig/gcc/testsuite/gcc.dg/anon-struct-6.c GCC/gcc/testsuite/gcc.dg/anon-struct-6.c
--- GCC.orig/gcc/testsuite/gcc.dg/anon-struct-6.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/anon-struct-6.c	2004-11-06 00:25:49.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test diagnostics for structure member with no type specifier or
+   declarator.  Test with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct s {
+  int a;
+  const;
+};
+/* { dg-warning "warning: useless type qualifier in empty declaration" "empty" { target *-*-* } 9 } */
+/* { dg-warning "warning: empty declaration" "empty" { target *-*-* } 9 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/anon-struct-7.c GCC/gcc/testsuite/gcc.dg/anon-struct-7.c
--- GCC.orig/gcc/testsuite/gcc.dg/anon-struct-7.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/anon-struct-7.c	2004-11-06 00:26:46.000000000 +0000
@@ -0,0 +1,10 @@
+/* Test diagnostics for structure member with no type specifier or
+   declarator.  Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+struct s {
+  int a;
+  const; /* { dg-warning "warning: ISO C forbids member declarations with no members" } */
+};
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/anon-struct-8.c GCC/gcc/testsuite/gcc.dg/anon-struct-8.c
--- GCC.orig/gcc/testsuite/gcc.dg/anon-struct-8.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/anon-struct-8.c	2004-11-06 00:27:04.000000000 +0000
@@ -0,0 +1,10 @@
+/* Test diagnostics for structure member with no type specifier or
+   declarator.  Test with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+struct s {
+  int a;
+  const; /* { dg-error "error: ISO C forbids member declarations with no members" } */
+};
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/bitfld-10.c GCC/gcc/testsuite/gcc.dg/bitfld-10.c
--- GCC.orig/gcc/testsuite/gcc.dg/bitfld-10.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/bitfld-10.c	2004-11-06 15:37:25.000000000 +0000
@@ -0,0 +1,8 @@
+/* Test for rejection of sizeof on bit-fields.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct { int a : 1; } x;
+
+int r = sizeof (x.a); /* { dg-error "error: 'sizeof' applied to a bit-field" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/bitfld-11.c GCC/gcc/testsuite/gcc.dg/bitfld-11.c
--- GCC.orig/gcc/testsuite/gcc.dg/bitfld-11.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/bitfld-11.c	2004-11-06 15:37:29.000000000 +0000
@@ -0,0 +1,8 @@
+/* Test for rejection of __alignof on bit-fields.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct { int a : 1; } x;
+
+int r = __alignof (x.a); /* { dg-error "error: '__alignof' applied to a bit-field" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/bitfld-12.c GCC/gcc/testsuite/gcc.dg/bitfld-12.c
--- GCC.orig/gcc/testsuite/gcc.dg/bitfld-12.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/bitfld-12.c	2004-11-06 15:41:49.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test for rejection of taking address of bit-fields.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+#include <stddef.h>
+
+struct s { int a : 1; } x, *y;
+
+int a = offsetof (struct s, a); /* { dg-error "error: attempt to take address of bit-field structure member 'a'" } */
+void *b = &x.a; /* { dg-error "error: cannot take address of bit-field 'a'" } */
+void *c = &y->a; /* { dg-error "error: cannot take address of bit-field 'a'" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/func-outside-1.c GCC/gcc/testsuite/gcc.dg/func-outside-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/func-outside-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/func-outside-1.c	2004-11-06 15:55:44.000000000 +0000
@@ -0,0 +1,9 @@
+/* Test for rejection of __func__ outside a function (GNU extensions
+   are OK there).  Test with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+const char *a = __func__; /* { dg-warning "warning: '__func__' is not defined outside of function scope" "undef" { target *-*-* } 0 } */
+const char *b = __FUNCTION__;
+const char *c = __PRETTY_FUNCTION__;
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/func-outside-2.c GCC/gcc/testsuite/gcc.dg/func-outside-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/func-outside-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/func-outside-2.c	2004-11-06 15:56:23.000000000 +0000
@@ -0,0 +1,9 @@
+/* Test for rejection of __func__ outside a function (GNU extensions
+   are OK there).  Test with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+const char *a = __func__; /* { dg-error "error: '__func__' is not defined outside of function scope" "undef" { target *-*-* } 0 } */
+const char *b = __FUNCTION__;
+const char *c = __PRETTY_FUNCTION__;
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/label-decl-1.c GCC/gcc/testsuite/gcc.dg/label-decl-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/label-decl-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/label-decl-1.c	2004-11-06 00:31:46.000000000 +0000
@@ -0,0 +1,17 @@
+/* Test diagnostics for label declarations.  Test with no special
+   options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+typedef int b;
+
+void
+f (void)
+{
+  __label__ a, b, c, d;
+  __extension__ (void)&&d; /* { dg-error "error: label 'd' used but not defined" } */
+  goto c; /* { dg-error "error: label 'c' used but not defined" } */
+ a: (void)0;
+ b: (void)0;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/label-decl-2.c GCC/gcc/testsuite/gcc.dg/label-decl-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/label-decl-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/label-decl-2.c	2004-11-06 00:33:19.000000000 +0000
@@ -0,0 +1,17 @@
+/* Test diagnostics for label declarations.  Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+typedef int b;
+
+void
+f (void)
+{
+  __label__ a, b, c, d;
+  __extension__ (void)&&d; /* { dg-error "error: label 'd' used but not defined" } */
+  /* { dg-warning "warning: ISO C forbids label declarations" "label decls" { target *-*-* } 12 } */
+  goto c; /* { dg-error "error: label 'c' used but not defined" } */
+ a: (void)0;
+ b: (void)0;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/label-decl-3.c GCC/gcc/testsuite/gcc.dg/label-decl-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/label-decl-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/label-decl-3.c	2004-11-06 18:05:02.000000000 +0000
@@ -0,0 +1,18 @@
+/* Test diagnostics for label declarations.  Test with
+   -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+typedef int b;
+
+void
+f (void)
+{
+  __label__ a, b, c, d;
+  __extension__ (void)&&d; /* { dg-error "error: label 'd' used but not defined" } */
+  /* { dg-error "error: ISO C forbids label declarations" "label decls" { target *-*-* } 13 } */
+  goto c; /* { dg-error "error: label 'c' used but not defined" } */
+ a: (void)0;
+ b: (void)0;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/label-decl-4.c GCC/gcc/testsuite/gcc.dg/label-decl-4.c
--- GCC.orig/gcc/testsuite/gcc.dg/label-decl-4.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/label-decl-4.c	2004-11-06 00:40:08.000000000 +0000
@@ -0,0 +1,14 @@
+/* Test diagnostics for duplicate label declarations.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (void)
+{
+  __label__ a, b, a; /* { dg-error "error: duplicate label declaration 'a'" } */
+  /* { dg-error "error: previous declaration of 'a' was here" "previous" { target *-*-* } 9 } */
+  __label__ c; /* { dg-error "error: previous declaration of 'c' was here" } */
+  __label__ c; /* { dg-error "error: duplicate label declaration 'c'" } */
+  return;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/struct-empty-1.c GCC/gcc/testsuite/gcc.dg/struct-empty-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/struct-empty-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/struct-empty-1.c	2004-11-06 16:19:12.000000000 +0000
@@ -0,0 +1,10 @@
+/* Test diagnostics for empty structures and unions.  Test with no
+   special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct s0 {};
+union u0 {};
+struct s1 { int : 1; };
+union u1 { int : 1; };
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/struct-empty-2.c GCC/gcc/testsuite/gcc.dg/struct-empty-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/struct-empty-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/struct-empty-2.c	2004-11-06 16:21:06.000000000 +0000
@@ -0,0 +1,10 @@
+/* Test diagnostics for empty structures and unions.  Test with
+   -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+struct s0 {}; /* { dg-warning "warning: struct has no members" } */
+union u0 {}; /* { dg-warning "warning: union has no members" } */
+struct s1 { int : 1; }; /* { dg-warning "warning: struct has no named members" } */
+union u1 { int : 1; }; /* { dg-warning "warning: union has no named members" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/struct-empty-3.c GCC/gcc/testsuite/gcc.dg/struct-empty-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/struct-empty-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/struct-empty-3.c	2004-11-06 16:21:22.000000000 +0000
@@ -0,0 +1,10 @@
+/* Test diagnostics for empty structures and unions.  Test with
+   -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+struct s0 {}; /* { dg-error "error: struct has no members" } */
+union u0 {}; /* { dg-error "error: union has no members" } */
+struct s1 { int : 1; }; /* { dg-error "error: struct has no named members" } */
+union u1 { int : 1; }; /* { dg-error "error: union has no named members" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/struct-semi-1.c GCC/gcc/testsuite/gcc.dg/struct-semi-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/struct-semi-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/struct-semi-1.c	2004-11-06 00:19:58.000000000 +0000
@@ -0,0 +1,19 @@
+/* Test diagnostics for missing and extra semicolons in structures.
+   Test with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct s0 { ; };
+struct s1 {
+  int a;
+  ;
+  int b;
+};
+struct s2 {
+  ;
+  int c
+}; /* { dg-warning "warning: no semicolon at end of struct or union" } */
+struct s3 {
+  int d
+}; /* { dg-warning "warning: no semicolon at end of struct or union" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/struct-semi-2.c GCC/gcc/testsuite/gcc.dg/struct-semi-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/struct-semi-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/struct-semi-2.c	2004-11-06 00:21:21.000000000 +0000
@@ -0,0 +1,20 @@
+/* Test diagnostics for missing and extra semicolons in structures.
+   Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+struct s0 { ; }; /* { dg-warning "warning: extra semicolon in struct or union specified" } */
+/* { dg-warning "warning: struct has no members" "empty" { target *-*-* } 7 } */
+struct s1 {
+  int a;
+  ; /* { dg-warning "warning: extra semicolon in struct or union specified" } */
+  int b;
+};
+struct s2 {
+  ; /* { dg-warning "warning: extra semicolon in struct or union specified" } */
+  int c
+}; /* { dg-warning "warning: no semicolon at end of struct or union" } */
+struct s3 {
+  int d
+}; /* { dg-warning "warning: no semicolon at end of struct or union" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/struct-semi-3.c GCC/gcc/testsuite/gcc.dg/struct-semi-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/struct-semi-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/struct-semi-3.c	2004-11-06 00:21:45.000000000 +0000
@@ -0,0 +1,20 @@
+/* Test diagnostics for missing and extra semicolons in structures.
+   Test with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+struct s0 { ; }; /* { dg-error "error: extra semicolon in struct or union specified" } */
+/* { dg-error "error: struct has no members" "empty" { target *-*-* } 7 } */
+struct s1 {
+  int a;
+  ; /* { dg-error "error: extra semicolon in struct or union specified" } */
+  int b;
+};
+struct s2 {
+  ; /* { dg-error "error: extra semicolon in struct or union specified" } */
+  int c
+}; /* { dg-error "error: no semicolon at end of struct or union" } */
+struct s3 {
+  int d
+}; /* { dg-error "error: no semicolon at end of struct or union" } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]