From b321a57a315097c60d058fb02bc13d847ecac880 Mon Sep 17 00:00:00 2001
From: manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sat, 16 Dec 2006 16:48:01 +0000
Subject: [PATCH] 2006-12-16  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	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.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119963 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                          | 10 ++++++++++
 gcc/c-common.c                         |  6 +++---
 gcc/c-opts.c                           |  7 +++++--
 gcc/c-parser.c                         |  4 ++--
 gcc/c.opt                              |  4 ++++
 gcc/doc/invoke.texi                    | 11 +++++++++--
 gcc/testsuite/ChangeLog                |  8 ++++++++
 gcc/testsuite/g++.dg/warn/empty-body.C |  2 +-
 gcc/testsuite/gcc.dg/20001116-1.c      |  2 +-
 gcc/testsuite/gcc.dg/if-empty-1.c      |  2 +-
 gcc/testsuite/gcc.dg/pr23165.c         |  2 +-
 11 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cd88ff9a7380..b17a039c26ad 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2006-12-16  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+	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  <jakub@redhat.com>
 
 	PR target/30185
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 4771a53ff24b..3219cf36067e 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 dcb68a16ffff..9a5d6f6ca3a3 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 d53b15526c1b..b688b15673ff 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 8582b20d5286..ab04dc2acac7 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 a4aae7ea1554..52b1daa18015 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 486bf17bd928..6d8074e2fc8a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2006-12-16  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+	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  <jvdelisle@gcc.gnu.org>
 
 	PR libfortran/30005
diff --git a/gcc/testsuite/g++.dg/warn/empty-body.C b/gcc/testsuite/g++.dg/warn/empty-body.C
index 6ca8900fda0c..064a09dde2e0 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 155cfe639624..3ea2f381d07e 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 a3156c1a7f87..9785c72a181e 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 <joseph@codesourcery.com> */
 /* { 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 2c63eb160903..94e7daebc90b 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)
-- 
GitLab