From: Manuel López-Ibáñez Date: Sat, 16 Dec 2006 16:48:01 +0000 (+0000) Subject: re PR middle-end/7651 (Define -Wextra strictly in terms of other warning flags) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3b433c507af133b95bfdbbd33338139e3d15345;p=platform%2Fupstream%2Fgcc.git re PR middle-end/7651 (Define -Wextra strictly in terms of other warning flags) 2006-12-16 Manuel Lopez-Ibanez PR middle-end/7651 * c.opt (Wempty-body): New. * doc/invoke.texi (Wempty-body): Document it. (Wextra): Enabled by -Wextra. * c-opts.c (c_common_post_options): Enabled by -Wextra. * c-common.c (empty_body_warning): Replace Wextra with Wempty-body. * c-parser.c (c_parser_c99_block_statement): Likewise. testsuite/ * gcc.dg/20001116-1.c: Replace -Wextra with -Wempty-body. * gcc.dg/if-empty-1.c: Likewise. * gcc.dg/pr23165.c: Likewise. * g++.dg/warn/empty-body.C: Likewise. From-SVN: r119963 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cd88ff9..b17a039 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2006-12-16 Manuel Lopez-Ibanez + + PR middle-end/7651 + * c.opt (Wempty-body): New. + * doc/invoke.texi (Wempty-body): Document it. + (Wextra): Enabled by -Wextra. + * c-opts.c (c_common_post_options): Enabled by -Wextra. + * c-common.c (empty_body_warning): Replace Wextra with Wempty-body. + * c-parser.c (c_parser_c99_block_statement): Likewise. + 2006-12-15 Jakub Jelinek PR target/30185 diff --git a/gcc/c-common.c b/gcc/c-common.c index 4771a53..3219cf3 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1000,7 +1000,7 @@ strict_aliasing_warning (tree otype, tree type, tree expr) void empty_body_warning (tree inner_then, tree inner_else) { - if (extra_warnings) + if (warn_empty_body) { if (TREE_CODE (inner_then) == STATEMENT_LIST && STATEMENT_LIST_TAIL (inner_then)) @@ -1011,11 +1011,11 @@ empty_body_warning (tree inner_then, tree inner_else) inner_else = STATEMENT_LIST_TAIL (inner_else)->stmt; if (IS_EMPTY_STMT (inner_then) && !inner_else) - warning (OPT_Wextra, "%Hempty body in an if-statement", + warning (OPT_Wempty_body, "%Hempty body in an if-statement", EXPR_LOCUS (inner_then)); if (inner_else && IS_EMPTY_STMT (inner_else)) - warning (OPT_Wextra, "%Hempty body in an else-statement", + warning (OPT_Wempty_body, "%Hempty body in an else-statement", EXPR_LOCUS (inner_else)); } } diff --git a/gcc/c-opts.c b/gcc/c-opts.c index dcb68a1..9a5d6f6 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -1025,8 +1025,11 @@ c_common_post_options (const char **pfilename) if (flag_objc_exceptions && !flag_objc_sjlj_exceptions) flag_exceptions = 1; - /* -Wextra implies -Wsign-compare, -Wmissing-field-initializers and - -Woverride-init, but not if explicitly overridden. */ + /* -Wextra implies -Wempty-body, -Wsign-compare, + -Wmissing-field-initializers and -Woverride-init, + but not if explicitly overridden. */ + if (warn_empty_body == -1) + warn_empty_body = extra_warnings; if (warn_sign_compare == -1) warn_sign_compare = extra_warnings; if (warn_missing_field_initializers == -1) diff --git a/gcc/c-parser.c b/gcc/c-parser.c index d53b155..b688b15 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -3832,7 +3832,7 @@ c_parser_c99_block_statement (c_parser *parser) is just parsing a statement but (a) it is a block in C99, (b) we track whether the body is an if statement for the sake of -Wparentheses warnings, (c) we handle an empty body specially for - the sake of -Wextra warnings. */ + the sake of -Wempty-body warnings. */ static tree c_parser_if_body (c_parser *parser, bool *if_p) @@ -3844,7 +3844,7 @@ c_parser_if_body (c_parser *parser, bool *if_p) && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) c_parser_label (parser); *if_p = c_parser_next_token_is_keyword (parser, RID_IF); - if (extra_warnings && c_parser_next_token_is (parser, CPP_SEMICOLON)) + if (warn_empty_body && c_parser_next_token_is (parser, CPP_SEMICOLON)) add_stmt (build_empty_stmt ()); c_parser_statement_after_labels (parser); return c_end_compound_stmt (block, flag_isoc99); diff --git a/gcc/c.opt b/gcc/c.opt index 8582b20..ab04dc2 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -173,6 +173,10 @@ Weffc++ C++ ObjC++ Var(warn_ecpp) Warn about violations of Effective C++ style rules +Wempty-body +C ObjC C++ ObjC++ Var(warn_empty_body) Init(-1) +Warn about an empty body in an if or else statement + Wendif-labels C ObjC C++ ObjC++ Warn about stray tokens after #elif and #endif diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a4aae7e..52b1daa 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -224,7 +224,8 @@ Objective-C and Objective-C++ Dialects}. -w -Wextra -Wall -Waggregate-return -Walways-true -Wno-attributes @gol -Wc++-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol -Wconversion -Wno-deprecated-declarations @gol --Wdisabled-optimization -Wno-div-by-zero -Wno-endif-labels @gol +-Wdisabled-optimization -Wno-div-by-zero @gol +-Wempty-body -Wno-endif-labels @gol -Werror -Werror-* -Werror-implicit-function-declaration @gol -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol -Wno-format-extra-args -Wformat-nonliteral @gol @@ -2915,7 +2916,8 @@ void foo(bar) @{ @} @end smallexample @item -An empty body occurs in an @samp{if} or @samp{else} statement. +An empty body occurs in an @samp{if} or @samp{else} statement. This +warning can be independently controlled by @option{-Wempty-body}. @item A pointer is compared against integer zero with @samp{<}, @samp{<=}, @@ -3165,6 +3167,11 @@ like @code{unsigned ui = -1}; and conversions to smaller types, like ((int) x)} and @code{ui = (unsigned) -1}, or if the value is not changed by the conversion like in @code{abs (2.0)}. +@item -Wempty-body +@opindex Wempty-body +An empty body occurs in an @samp{if} or @samp{else} statement. +This warning is also enabled by @option{-Wextra}. + @item -Wsign-compare @opindex Wsign-compare @cindex warning for comparison of signed and unsigned values diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 486bf17..6d8074e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2006-12-16 Manuel Lopez-Ibanez + + PR middle-end/7651 + * gcc.dg/20001116-1.c: Replace -Wextra with -Wempty-body. + * gcc.dg/if-empty-1.c: Likewise. + * gcc.dg/pr23165.c: Likewise. + * g++.dg/warn/empty-body.C: Likewise. + 2006-12-15 Jerry DeLisle PR libfortran/30005 diff --git a/gcc/testsuite/g++.dg/warn/empty-body.C b/gcc/testsuite/g++.dg/warn/empty-body.C index 6ca8900..064a09d 100644 --- a/gcc/testsuite/g++.dg/warn/empty-body.C +++ b/gcc/testsuite/g++.dg/warn/empty-body.C @@ -1,5 +1,5 @@ // PR c++/5520 -// { dg-options "-O2 -Wextra" } +// { dg-options "-O2 -Wempty-body" } void breakme() { diff --git a/gcc/testsuite/gcc.dg/20001116-1.c b/gcc/testsuite/gcc.dg/20001116-1.c index 155cfe6..3ea2f38 100644 --- a/gcc/testsuite/gcc.dg/20001116-1.c +++ b/gcc/testsuite/gcc.dg/20001116-1.c @@ -2,7 +2,7 @@ nasty ICE due to messed up parser context. Problem originally found during bootstrap; this is synthetic. -zw */ /* { dg-do compile } - { dg-options -W } */ + { dg-options -Wempty-body } */ void foo (int x) { diff --git a/gcc/testsuite/gcc.dg/if-empty-1.c b/gcc/testsuite/gcc.dg/if-empty-1.c index a3156c1..9785c72 100644 --- a/gcc/testsuite/gcc.dg/if-empty-1.c +++ b/gcc/testsuite/gcc.dg/if-empty-1.c @@ -1,7 +1,7 @@ /* Test diagnostics for empty bodies in if / else. */ /* Origin: Joseph Myers */ /* { dg-do compile } */ -/* { dg-options "-Wextra" } */ +/* { dg-options "-Wempty-body" } */ void f (int x) diff --git a/gcc/testsuite/gcc.dg/pr23165.c b/gcc/testsuite/gcc.dg/pr23165.c index 2c63eb1..94e7dae 100644 --- a/gcc/testsuite/gcc.dg/pr23165.c +++ b/gcc/testsuite/gcc.dg/pr23165.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wextra" } */ +/* { dg-options "-Wempty-body" } */ void foo (void) { if (0)