]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2007-03-14 Dirk Mueller <dmueller@suse.de>
authormueller <mueller@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Mar 2007 19:33:17 +0000 (19:33 +0000)
committermueller <mueller@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Mar 2007 19:33:17 +0000 (19:33 +0000)
        * c-common.h (empty_body_warning): Rename to empty_if_body_warning.
        * c-common.c (empty_if_body_warning): Rephrase diagnostic message.
        * c-parser.c (c_parser_if_body): Always add an empty statement in case
        of empty body.
        * c-parser.c (c_parser_do_statement): Warn about empty body in
        do/while statement.
        * c-typeck (c_finish_if_stmt): Call empty_if_body_warning.
        * doc/invoke.texi (-Wempty-body): Update documentation.

        * cp/semantics.c (c_finish_if_stmt): Call empty_if_body_warning.
        (finish_do_body): Warn about empty body in do/while statement.

        * g++.dg/warn/do-empty.C: New.
        * gcc.dg/do-empty.c: New.
        * gcc.dg/if-empty-1.c: Update.
        * gcc.dg/20001116-1.c: Update.
        * gcc.dg/pr23165.c: Update.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122928 138bc75d-0d04-0410-961f-82ee72b054a4

14 files changed:
gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-parser.c
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/do-empty.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/20001116-1.c
gcc/testsuite/gcc.dg/do-empty.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/if-empty-1.c
gcc/testsuite/gcc.dg/pr23165.c

index 3dbd1301cec8832efcc9541fdec348e1e0d8f725..1259974f21fa2aeed2f9852aeac510ce6174441e 100644 (file)
@@ -1,3 +1,14 @@
+2007-03-14  Dirk Mueller  <dmueller@suse.de>
+
+       * c-common.h (empty_body_warning): Rename to empty_if_body_warning.
+       * c-common.c (empty_if_body_warning): Rephrase diagnostic message.
+       * c-parser.c (c_parser_if_body): Always add an empty statement in case
+       of empty body.
+       * c-parser.c (c_parser_do_statement): Warn about empty body in
+       do/while statement.
+       * c-typeck (c_finish_if_stmt): Call empty_if_body_warning.
+       * doc/invoke.texi (-Wempty-body): Update documentation.
+
 2007-03-14  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR c/21438
index f82a84b59145dec75bded0179580e90a77357cb9..36b87eba20620aae32c881b055c72d4d30910bb8 100644 (file)
@@ -1056,26 +1056,23 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
    block.  */
 
 void
-empty_body_warning (tree inner_then, tree inner_else)
+empty_if_body_warning (tree inner_then, tree inner_else)
 {
-  if (warn_empty_body)
-    {
-      if (TREE_CODE (inner_then) == STATEMENT_LIST
-         && STATEMENT_LIST_TAIL (inner_then))
-       inner_then = STATEMENT_LIST_TAIL (inner_then)->stmt;
+  if (TREE_CODE (inner_then) == STATEMENT_LIST
+      && STATEMENT_LIST_TAIL (inner_then))
+    inner_then = STATEMENT_LIST_TAIL (inner_then)->stmt;
 
-      if (inner_else && TREE_CODE (inner_else) == STATEMENT_LIST
-         && STATEMENT_LIST_TAIL (inner_else))
-       inner_else = STATEMENT_LIST_TAIL (inner_else)->stmt;
+  if (inner_else && TREE_CODE (inner_else) == STATEMENT_LIST
+      && STATEMENT_LIST_TAIL (inner_else))
+    inner_else = STATEMENT_LIST_TAIL (inner_else)->stmt;
 
-      if (IS_EMPTY_STMT (inner_then) && !inner_else)
-       warning (OPT_Wempty_body, "%Hempty body in an if-statement",
-                EXPR_LOCUS (inner_then));
+  if (IS_EMPTY_STMT (inner_then) && !inner_else)
+    warning (OPT_Wempty_body, "%Hsuggest braces around empty body "
+             "in an %<if%> statement", EXPR_LOCUS (inner_then));
 
-      if (inner_else && IS_EMPTY_STMT (inner_else))
-       warning (OPT_Wempty_body, "%Hempty body in an else-statement",
-                EXPR_LOCUS (inner_else));
-   }
+  else if (inner_else && IS_EMPTY_STMT (inner_else))
+    warning (OPT_Wempty_body, "%Hsuggest braces around empty body "
+             "in an %<else%> statement", EXPR_LOCUS (inner_else));
 }
 
 /* Warn for unlikely, improbable, or stupid DECL declarations
index b2739c3efb325d3ca2d783e9ba00015e24876f76..08ce4600ee69d911d1571ca744efcf0a46636995 100644 (file)
@@ -670,7 +670,7 @@ extern tree fix_string_type (tree);
 struct varray_head_tag;
 extern void constant_expression_warning (tree);
 extern void strict_aliasing_warning (tree, tree, tree);
-extern void empty_body_warning (tree, tree);
+extern void empty_if_body_warning (tree, tree);
 extern tree convert_and_check (tree, tree);
 extern void overflow_warning (tree);
 extern void warn_logical_operator (enum tree_code, tree, tree);
index 665b494e231cb2f91139013eda6959ff2522f2b3..b1f40a47faa88d0134c16041d4d63a97c0b5e0db 100644 (file)
@@ -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 (warn_empty_body && c_parser_next_token_is (parser, CPP_SEMICOLON))
+  if (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);
@@ -3953,6 +3953,9 @@ c_parser_do_statement (c_parser *parser)
   location_t loc;
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
   c_parser_consume_token (parser);
+  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
+    warning (OPT_Wempty_body,
+             "suggest braces around empty body in %<do%> statement");
   block = c_begin_compound_stmt (flag_isoc99);
   loc = c_parser_peek_token (parser)->location;
   save_break = c_break_label;
index eca10668ee659b8c8c4318b91682e81ea7c5b2a8..6986405e8a98e9f2c1d00129d35b58b1d4f35c03 100644 (file)
@@ -7229,7 +7229,7 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
                  &if_locus);
     }
 
-  empty_body_warning (then_block, else_block);
+  empty_if_body_warning (then_block, else_block);
 
   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
   SET_EXPR_LOCATION (stmt, if_locus);
index e324712dd47fa70482019a646d662ee9d996bbfd..1409d2b974ae2623ca761c219d37794cc8eec59a 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-14  Dirk Mueller  <dmueller@suse.de>
+
+       * cp/semantics.c (c_finish_if_stmt): Call empty_if_body_warning.
+       (finish_do_body): Warn about empty body in do/while statement.
+
 2007-03-14  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        * class.c (warn_hidden): Add OPT_Woverloaded_virtual to warning.
index e016b0a40dec0b28ab221784711ee2a6a62da8b3..e2603531e881e796aa3d6ae9bc18278ca8a8b5e2 100644 (file)
@@ -701,7 +701,7 @@ finish_if_stmt (tree if_stmt)
   TREE_CHAIN (if_stmt) = NULL;
   add_stmt (do_poplevel (scope));
   finish_stmt ();
-  empty_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
+  empty_if_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
 }
 
 /* Begin a while-statement.  Returns a newly created WHILE_STMT if
@@ -754,7 +754,14 @@ begin_do_stmt (void)
 void
 finish_do_body (tree do_stmt)
 {
-  DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
+  tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
+
+  if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
+    body = STATEMENT_LIST_TAIL (body)->stmt;
+
+  if (IS_EMPTY_STMT (body))
+    warning (OPT_Wempty_body,
+            "suggest explicit braces around empty body in %<do%> statement");
 }
 
 /* Finish a do-statement, which may be given by DO_STMT, and whose
index e8f184d48becd96b6bce86a9ee9dec12a1bb719b..fa9ed7f4d2b2592f3ac5a8e99605325041848ada 100644 (file)
@@ -3136,8 +3136,9 @@ functions.  This warning can be independently controlled by
 @option{-Wmissing-parameter-type}.
 
 @item
-An empty body occurs in an @samp{if} or @samp{else} statement. This
-warning can be independently controlled by @option{-Wempty-body}.
+An empty body occurs in an @samp{if}, @samp{else} or
+@samp{do while} statement. This warning can be independently
+controlled by @option{-Wempty-body}.
 
 @item
 A pointer is compared against integer zero with @samp{<}, @samp{<=},
@@ -3397,8 +3398,8 @@ 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}.
+An empty body occurs in an @samp{if}, @samp{else} or @samp{do while}
+statement.  This warning is also enabled by @option{-Wextra}.
 
 @item -Wsign-compare
 @opindex Wsign-compare
index d3713ed19ec978f790aa901f924cac92a16e01b1..e0d27c55562265cf937b4965414a376e32164c68 100644 (file)
@@ -1,3 +1,11 @@
+2007-03-14  Dirk Mueller  <dmueller@suse.de>
+
+       * g++.dg/warn/do-empty.C: New.
+       * gcc.dg/do-empty.c: New.
+       * gcc.dg/if-empty-1.c: Update.
+       * gcc.dg/20001116-1.c: Update.
+       * gcc.dg/pr23165.c: Update.
+
 2007-03-14  Jakub Jelinek  <jakub@redhat.com>
 
        * gfortran.dg/module_implicit_conversion.f90: New test.
diff --git a/gcc/testsuite/g++.dg/warn/do-empty.C b/gcc/testsuite/g++.dg/warn/do-empty.C
new file mode 100644 (file)
index 0000000..350261d
--- /dev/null
@@ -0,0 +1,15 @@
+/* Test diagnostics for empty bodies in do / while.  */
+/* { dg-do compile } */
+/* { dg-options "-Wempty-body" } */
+
+void
+f (int x)
+{
+  do
+    ; /* { dg-warning "empty body in" } */
+  while (x--);
+
+  do
+  {} /* { dg-bogus "empty body in" } */
+  while (++x < 10);
+}
index 3ea2f381d07e7100025f9e588c299900aa26dbd9..8b1e919c66fbcc7bc17077ff601239e195b222e8 100644 (file)
@@ -7,5 +7,5 @@
 void foo (int x)
 {
   if (x)
-    ;  /* { dg-warning "empty body in an if-statement" } */
+    ;  /* { dg-warning "empty body in an" } */
 }
diff --git a/gcc/testsuite/gcc.dg/do-empty.c b/gcc/testsuite/gcc.dg/do-empty.c
new file mode 100644 (file)
index 0000000..350261d
--- /dev/null
@@ -0,0 +1,15 @@
+/* Test diagnostics for empty bodies in do / while.  */
+/* { dg-do compile } */
+/* { dg-options "-Wempty-body" } */
+
+void
+f (int x)
+{
+  do
+    ; /* { dg-warning "empty body in" } */
+  while (x--);
+
+  do
+  {} /* { dg-bogus "empty body in" } */
+  while (++x < 10);
+}
index 9785c72a181e0a97a68cef92d880b7d0967b7794..a129832c337adb8aa523a560eb66d35b06099141 100644 (file)
@@ -7,7 +7,7 @@ void
 f (int x)
 {
   if (x)
-    ; /* { dg-warning "warning: empty body in an if-statement" } */
+    ; /* { dg-warning "warning: empty body in an" } */
   if (x)
     ; /* By design we don't warn in this case.  */
   else
@@ -15,7 +15,7 @@ f (int x)
   if (x)
     (void)0;
   else
-    ; /* { dg-warning "warning: empty body in an else-statement" } */
+    ; /* { dg-warning "warning: empty body in an" } */
   if (x)
     (void)0;
   else
index 94e7daebc90b7817ad92f6c3b77fffa376d3cdfd..49194a1462d14ef3034ad68bd3efd694f808fcbd 100644 (file)
@@ -3,7 +3,7 @@
 void foo (void)
 {
        if (0)
-         a: ; /* { dg-warning "empty body in an if-statement" } */
+         a: ; /* { dg-warning "empty body in an" } */
 
 
 }