This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to diagnostic for data definitions without declspecs
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 26 Oct 2004 21:02:30 +0000 (UTC)
- Subject: Patch to diagnostic for data definitions without declspecs
Declarations at top level such as "foo();" receive from the present C
parser a warning which becomes an error with -pedantic. This is a
misuse of pedantic; it is -pedantic-errors which should change
warnings into errors, not -pedantic. This patch accordingly fixes
this to be an unconditional pedwarn instead; the corresponding change
I've made to my new parser gets rid of one further ??? comment.
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline.
--
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-10-26 Joseph S. Myers <jsm@polyomino.org.uk>
* c-parse.in (datadef): Use pedwarn rather than error and warning
for diagnostic in case of no declaration specifiers.
testsuite:
2004-10-26 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/decl-nospec-1.c, gcc.dg/decl-nospec-2.c,
gcc.dg/decl-nospec-3.c: New tests.
diff -rupN GCC.orig/gcc/c-parse.in GCC/gcc/c-parse.in
--- GCC.orig/gcc/c-parse.in 2004-10-26 16:28:08.000000000 +0000
+++ GCC/gcc/c-parse.in 2004-10-26 16:31:22.000000000 +0000
@@ -407,11 +407,7 @@ save_obstack_position:
datadef:
setspecs notype_initdecls ';'
- { if (pedantic)
- error ("ISO C forbids data definition with no type or storage class");
- else
- warning ("data definition has no type or storage class");
-
+ { pedwarn ("data definition has no type or storage class");
POP_DECLSPEC_STACK; }
| declspecs_nots setspecs notype_initdecls ';'
{ POP_DECLSPEC_STACK; }
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/decl-nospec-1.c GCC/gcc/testsuite/gcc.dg/decl-nospec-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/decl-nospec-1.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/decl-nospec-1.c 2004-10-26 16:34:09.000000000 +0000
@@ -0,0 +1,8 @@
+/* Data definition with no type or storage class should receive a
+ pedwarn, rather than a warning which becomes an error with
+ -pedantic. Test with no options. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+foo(); /* { dg-warning "warning: data definition has no type or storage class" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/decl-nospec-2.c GCC/gcc/testsuite/gcc.dg/decl-nospec-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/decl-nospec-2.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/decl-nospec-2.c 2004-10-26 16:34:34.000000000 +0000
@@ -0,0 +1,8 @@
+/* Data definition with no type or storage class should receive a
+ pedwarn, rather than a warning which becomes an error with
+ -pedantic. Test with -pedantic. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+foo(); /* { dg-warning "warning: data definition has no type or storage class" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/decl-nospec-3.c GCC/gcc/testsuite/gcc.dg/decl-nospec-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/decl-nospec-3.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/decl-nospec-3.c 2004-10-26 16:34:55.000000000 +0000
@@ -0,0 +1,8 @@
+/* Data definition with no type or storage class should receive a
+ pedwarn, rather than a warning which becomes an error with
+ -pedantic. Test with -pedantic-errors. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+foo(); /* { dg-error "error: data definition has no type or storage class" } */