Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 119813) +++ gcc/doc/invoke.texi (working copy) @@ -2916,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{<=}, Index: gcc/testsuite/gcc.dg/20001116-1.c =================================================================== --- gcc/testsuite/gcc.dg/20001116-1.c (revision 119813) +++ gcc/testsuite/gcc.dg/20001116-1.c (working copy) @@ -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) { Index: gcc/testsuite/gcc.dg/if-empty-1.c =================================================================== --- gcc/testsuite/gcc.dg/if-empty-1.c (revision 119813) +++ gcc/testsuite/gcc.dg/if-empty-1.c (working copy) @@ -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) Index: gcc/testsuite/gcc.dg/pr23165.c =================================================================== --- gcc/testsuite/gcc.dg/pr23165.c (revision 119813) +++ gcc/testsuite/gcc.dg/pr23165.c (working copy) @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wextra" } */ +/* { dg-options "-Wempty-body" } */ void foo (void) { if (0) Index: gcc/testsuite/g++.dg/warn/empty-body.C =================================================================== --- gcc/testsuite/g++.dg/warn/empty-body.C (revision 119813) +++ gcc/testsuite/g++.dg/warn/empty-body.C (working copy) @@ -1,5 +1,5 @@ // PR c++/5520 -// { dg-options "-O2 -Wextra" } +// { dg-options "-O2 -Wempty-body" } void breakme() { Index: gcc/c.opt =================================================================== --- gcc/c.opt (revision 119813) +++ gcc/c.opt (working copy) @@ -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 Index: gcc/c-opts.c =================================================================== --- gcc/c-opts.c (revision 119813) +++ gcc/c-opts.c (working copy) @@ -1025,8 +1025,11 @@ c_common_post_options (const char **pfil 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) Index: gcc/c-common.c =================================================================== --- gcc/c-common.c (revision 119813) +++ gcc/c-common.c (working copy) @@ -1000,7 +1000,7 @@ strict_aliasing_warning (tree otype, tre 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, tre 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)); } } Index: gcc/c-parser.c =================================================================== --- gcc/c-parser.c (revision 119813) +++ gcc/c-parser.c (working copy) @@ -3832,7 +3832,7 @@ c_parser_c99_block_statement (c_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 && 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);