diff options
-rw-r--r-- | gcc/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/c-common.c | 4 | ||||
-rw-r--r-- | gcc/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-errors.c | 18 | ||||
-rw-r--r-- | gcc/c-opts.c | 4 | ||||
-rw-r--r-- | gcc/c-parse.in | 7 | ||||
-rw-r--r-- | gcc/c-tree.h | 1 | ||||
-rw-r--r-- | gcc/c.opt | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 10 |
9 files changed, 66 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 372f834..b7ac766 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/c-common.c b/gcc/c-common.c index 2e985c2..c579b16 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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. */ diff --git a/gcc/c-common.h b/gcc/c-common.h index f46058f..5d4c3d4 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -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. */ diff --git a/gcc/c-errors.c b/gcc/c-errors.c index 2a2fdc0..fa71b8c 100644 --- a/gcc/c-errors.c +++ b/gcc/c-errors.c @@ -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); +} diff --git a/gcc/c-opts.c b/gcc/c-opts.c index a6dd9f0..5061a58 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -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; diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 8ac1412..22b1531 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -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 ; diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 0a36609..cbc83a5 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -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); @@ -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 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5393d10..edd657d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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. |