]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-parse.in (lineno_stmt_decl_or_labels_ending_decl): Also warn when warn_declaration_...
authorHans-Peter Nilsson <hp@bitrange.com>
Mon, 28 Jul 2003 20:03:25 +0000 (20:03 +0000)
committerHans-Peter Nilsson <hp@gcc.gnu.org>
Mon, 28 Jul 2003 20:03:25 +0000 (20:03 +0000)
* c-parse.in (lineno_stmt_decl_or_labels_ending_decl): Also warn
when warn_declaration_after_statement.  Call pedwarn_c90, not
pedwarn.  Correct message: it's "ISO C90", not "ISO C89".
* c-common.c (warn_declaration_after_statement): Define.
* c-common.h (warn_declaration_after_statement): Declare.
* c.opt (Wdeclaration-after-statement): New.
* c-errors.c (pedwarn_c90): New function.
* c-opts.c (c_common_handle_option) <case
OPT_Wdeclaration_after_statement>: New.
* c-tree.h (pedwarn_c90): Declare.
* doc/invoke.texi (Option Summary): Document
-Wdeclaration-after-statement.
(Warning Options): Ditto.

Co-Authored-By: Michael Culbertson <Michael.J.Culbertson@wheaton.edu>
From-SVN: r69899

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-errors.c
gcc/c-opts.c
gcc/c-parse.in
gcc/c-tree.h
gcc/c.opt
gcc/doc/invoke.texi

index 372f834b9f5c51e9c4ce9e929efdb3a846087d03..b7ac766e232fbf1367bdb8c9443a56b28b33f9ea 100644 (file)
@@ -1,3 +1,20 @@
+2003-07-28  Hans-Peter Nilsson  <hp@bitrange.com>
+           Michael Culbertson  <Michael.J.Culbertson@wheaton.edu>
+
+       * c-parse.in (lineno_stmt_decl_or_labels_ending_decl): Also warn
+       when warn_declaration_after_statement.  Call pedwarn_c90, not
+       pedwarn.  Correct message: it's "ISO C90", not "ISO C89".
+       * c-common.c (warn_declaration_after_statement): Define.
+       * c-common.h (warn_declaration_after_statement): Declare.
+       * c.opt (Wdeclaration-after-statement): New.
+       * c-errors.c (pedwarn_c90): New function.
+       * c-opts.c (c_common_handle_option) <case
+       OPT_Wdeclaration_after_statement>: New.
+       * c-tree.h (pedwarn_c90): Declare.
+       * doc/invoke.texi (Option Summary): Document
+       -Wdeclaration-after-statement.
+       (Warning Options): Ditto.
+
 Mon Jul 28 20:13:06 CEST 2003  Jan Hubicka  <jh@suse.cz>
 
        * i386.md (memory attribute) Avoid accessing uninitialized memory
index 2e985c2a4d2c32d4bb93fcab67363ee6b9a13923..c579b16f37c3377470f62e7cbb81ec68f89573dc 100644 (file)
@@ -391,6 +391,10 @@ int warn_bad_function_cast;
 
 int warn_traditional;
 
+/* Nonzero means warn for a declaration found after a statement.  */
+
+int warn_declaration_after_statement;
+
 /* Nonzero means warn for non-prototype function decls
    or non-prototyped defs without previous prototype.  */
 
index f46058f8b4e289638c4a665ba851772e4c87b4cf..5d4c3d42d5a17c805beda4d40188e0f4bed2443a 100644 (file)
@@ -569,6 +569,10 @@ extern int warn_bad_function_cast;
 
 extern int warn_traditional;
 
+/* Nonzero means warn for a declaration found after a statement.  */
+
+extern int warn_declaration_after_statement;
+
 /* Nonzero means warn for non-prototype function decls
    or non-prototyped defs without previous prototype.  */
 
index 2a2fdc0c440cf87f22af9e44c690f6e57d4f0c6d..fa71b8cfa97d92f5830e2272b6bdc121d37d954b 100644 (file)
@@ -43,3 +43,21 @@ pedwarn_c99 (const char *msgid, ...)
   report_diagnostic (&diagnostic);
   va_end (ap);
 }
+
+/* Issue an ISO C90 pedantic warning MSGID.  This function is supposed to
+   be used for matters that are allowed in ISO C99 but not supported in
+   ISO C90, thus we explicitly don't pedwarn when C99 is specified.
+   (There is no flag_c90.)  */
+
+void
+pedwarn_c90 (const char *msgid, ...)
+{
+  diagnostic_info diagnostic;
+  va_list ap;
+
+  va_start (ap, msgid);
+  diagnostic_set_info (&diagnostic, msgid, &ap, input_location,
+                       flag_isoc99 ? DK_WARNING : pedantic_error_kind ());
+  report_diagnostic (&diagnostic);
+  va_end (ap);
+}
index a6dd9f0a5c84196c801f307ec9eff57f627f5e4e..5061a58e9f166c955aa0eb503a4e63dbb20926c3 100644 (file)
@@ -412,6 +412,10 @@ c_common_handle_option (size_t scode, const char *arg, int value)
       warn_ctor_dtor_privacy = value;
       break;
 
+    case OPT_Wdeclaration_after_statement:
+      warn_declaration_after_statement = value;
+      break;
+
     case OPT_Wdeprecated:
       warn_deprecated = value;
       cpp_opts->warn_deprecated = value;
index 8ac14120e6f8921c12b4292b44ce5c99c4b7b504..22b1531afa1355e341c85feb9bb1f5109427228c 100644 (file)
@@ -2013,8 +2013,11 @@ lineno_stmt_decl_or_labels_ending_stmt:
 lineno_stmt_decl_or_labels_ending_decl:
          lineno_decl
        | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
-               { if (pedantic && !flag_isoc99)
-                   pedwarn ("ISO C89 forbids mixed declarations and code"); }
+               {
+                 if ((pedantic && !flag_isoc99)
+                     || warn_declaration_after_statement)
+                   pedwarn_c90 ("ISO C90 forbids mixed declarations and code");
+               }
        | lineno_stmt_decl_or_labels_ending_decl lineno_decl
        | lineno_stmt_decl_or_labels_ending_error lineno_decl
        ;
index 0a36609093af40946371d059ddc32d2d3a1ec93a..cbc83a523a0c57b314969b97d01892f38a18ce2e 100644 (file)
@@ -288,6 +288,7 @@ extern void set_init_index (tree, tree);
 extern void set_init_label (tree);
 extern void process_init_element (tree);
 extern tree build_compound_literal (tree, tree);
+extern void pedwarn_c90 (const char *, ...) ATTRIBUTE_PRINTF_1;
 extern void pedwarn_c99 (const char *, ...) ATTRIBUTE_PRINTF_1;
 extern tree c_start_case (tree);
 extern void c_finish_case (void);
index 042f4cfc86db1b024b3a37712aaeda7f261377ec..15b96ad5e826442261fff55554d889c6dafeb0a3 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -180,6 +180,10 @@ Wctor-dtor-privacy
 C++ ObjC++
 Warn when all constructors and destructors are private
 
+Wdeclaration-after-statement
+C ObjC
+Warn when a declaration is found after a statement
+
 Wdeprecated
 C++ ObjC++
 Warn about deprecated compiler features
index 5393d1081348f1433b933c805eb0929af100358d..edd657d759913b204be3ff0505ecf16f2b3dd340 100644 (file)
@@ -233,7 +233,8 @@ in the following sections.
 @item C-only Warning Options
 @gccoptlist{-Wbad-function-cast  -Wmissing-declarations @gol
 -Wmissing-prototypes  -Wnested-externs @gol
--Wstrict-prototypes  -Wtraditional}
+-Wstrict-prototypes  -Wtraditional @gol
+-Wdeclaration-after-statement}
 
 @item Debugging Options
 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
@@ -2609,6 +2610,13 @@ 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.  @xref{Mixed Declarations}.
+
 @item -Wundef
 @opindex Wundef
 Warn if an undefined identifier is evaluated in an @samp{#if} directive.