+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
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. */
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. */
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);
+}
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;
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
;
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);
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
@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}.
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.