Commit 85617eba by Hans-Peter Nilsson Committed by Hans-Peter Nilsson

c-parse.in (lineno_stmt_decl_or_labels_ending_decl): Also warn when…

c-parse.in (lineno_stmt_decl_or_labels_ending_decl): Also warn when warn_declaration_after_statement.

	* 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
parent f527d196
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
......
......@@ -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. */
......
......@@ -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. */
......
......@@ -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);
}
......@@ -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;
......
......@@ -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
;
......
......@@ -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
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment