Take 2: Re: [RFA:] -Wdeclaration-after-statement
Hans-Peter Nilsson
hp@bitrange.com
Wed Jul 16 10:36:00 GMT 2003
Thanks for the review!
On Wed, 16 Jul 2003, Joseph S. Myers wrote:
> On Wed, 16 Jul 2003, Hans-Peter Nilsson wrote:
>
> > testsuite:
> > * gcc.dg/c99-mixdecl-2.c, gcc.dg/c90-mixdecl-2.c: New tests.
>
> c9?-*.c are tests of standards versions support, tests of a particular
> warning option should be named differently. (I'd be happy with
> Wdeclaration-after-statement-[12].c, but maybe some people would dislike
> those long filenames.)
I don't mind. Cross-references to the c9?-mixdecl* tests now
seemed in order.
> > + @item -Wdeclaration-after-statement @r{(C only)}
> > + @opindex Wdeclaration-after-statement
> > + Warn when a declaration is found after a statement in a block. This
> > + construct, known from C++, was introduced with ISO C99 and is by default
> > + allowed in gcc. It is disallowed in ISO C90 and in gcc versions before
> > + GCC version 3.0.
>
> I would say "was not supported by GCC versions before GCC 3.0" rather than
> saying that such versions disallow it.
Ok.
> Also, "GCC" rather than "gcc".
Hah! Your attempt to trick me to a texinfo punctuation error
has been thwarted! :-)
> > + /* Test for C99 mixed declarations and code giving warnings, not error with
> > + -Wdeclaration-after-statement. */
>
> dg-warning and dg-error don't suffice to distinguish warnings and errors:
> you probably want dg-warning "warning" here to detect the "warning"
> marker.
Well I'll be... I changed those dg-warning:s to dg-error and
the tests still passed! Updated parts below. ChangeLog entry
for invoke.texi as before. Tested on cross to
mmix-knuth-mmixware. Doc change tested as before.
testsuite:
* gcc.dg/Wdeclaration-after-statement-1.c,
gcc.dg/Wdeclaration-after-statement-2.c: New tests.
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.318
diff -p -c -r1.318 invoke.texi
*** doc/invoke.texi 12 Jul 2003 01:07:40 -0000 1.318
--- doc/invoke.texi 16 Jul 2003 10:27:42 -0000
*************** in the following sections.
*** 233,239 ****
@item C-only Warning Options
@gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
-Wmissing-prototypes -Wnested-externs @gol
! -Wstrict-prototypes -Wtraditional}
@item Debugging Options
@xref{Debugging Options,,Options for Debugging Your Program or GCC}.
--- 233,240 ----
@item C-only Warning Options
@gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
-Wmissing-prototypes -Wnested-externs @gol
! -Wstrict-prototypes -Wtraditional @gol
! -Wdeclaration-after-statement}
@item Debugging Options
@xref{Debugging Options,,Options for Debugging Your Program or GCC}.
*************** libiberty's traditional C compatibility
*** 2608,2613 ****
--- 2609,2621 ----
because that feature is already a gcc extension and thus not relevant to
traditional C compatibility.
@end itemize
+
+ @item -Wdeclaration-after-statement @r{(C only)}
+ @opindex Wdeclaration-after-statement
+ Warn when a declaration is found after a statement in a block. This
+ construct, known from C++, was introduced with ISO C99 and is by default
+ allowed in GCC@. It is not supported by ISO C90 and was not supported by
+ GCC versions before GCC 3.0.
@item -Wundef
@opindex Wundef
*** /dev/null Tue Jan 1 05:00:00 1980
--- gcc.dg/Wdeclaration-after-statement-1.c Wed Jul 16 11:46:50 2003
***************
*** 0 ****
--- 1,26 ----
+ /* Test for -Wdeclaration-after-statement emitting warnings when no
+ standard-specifying option is given. See also c9?-mixdecl-*. */
+ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+ /* { dg-do run } */
+ /* { dg-options "-Wdeclaration-after-statement" } */
+
+ extern void abort (void);
+ extern void exit (int);
+
+ int
+ main (void)
+ {
+ int i = 0;
+ if (i != 0)
+ abort ();
+ i++;
+ if (i != 1)
+ abort ();
+ int j = i; /* { dg-warning "warning" "declaration after statement" } */
+ if (j != 1)
+ abort ();
+ struct foo { int i0; } k = { 4 }; /* { dg-warning "warning" "declaration after statement" } */
+ if (k.i0 != 4)
+ abort ();
+ exit (0);
+ }
*** /dev/null Tue Jan 1 05:00:00 1980
--- gcc.dg/Wdeclaration-after-statement-2.c Wed Jul 16 11:46:30 2003
***************
*** 0 ****
--- 1,26 ----
+ /* Test for C99 mixed declarations and code giving warnings, not error with
+ -Wdeclaration-after-statement. See also c9?-mixdecl-*. */
+ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+ /* { dg-do run } */
+ /* { dg-options "-std=c99 -pedantic-errors -Wdeclaration-after-statement" } */
+
+ extern void abort (void);
+ extern void exit (int);
+
+ int
+ main (void)
+ {
+ int i = 0;
+ if (i != 0)
+ abort ();
+ i++;
+ if (i != 1)
+ abort ();
+ int j = i; /* { dg-warning "warning" "declaration-after-statement" } */
+ if (j != 1)
+ abort ();
+ struct foo { int i0; } k = { 4 }; /* { dg-warning "warning" "declaration-after-statement" } */
+ if (k.i0 != 4)
+ abort ();
+ exit (0);
+ }
brgds, H-P
More information about the Gcc-patches
mailing list