aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2008-09-30 09:52:41 +0000
committerPaolo Bonzini <bonzini@gcc.gnu.org>2008-09-30 09:52:41 +0000
commit626c34b5c945cc9c577bd0509d297b81df083d3f (patch)
tree550e5d90532796178dbba4eb2e6ff1c54828d12c /gcc
parentb5d60b839fd858c794384f4e6bf18005211e7add (diff)
downloadgcc-626c34b5c945cc9c577bd0509d297b81df083d3f.zip
gcc-626c34b5c945cc9c577bd0509d297b81df083d3f.tar.gz
gcc-626c34b5c945cc9c577bd0509d297b81df083d3f.tar.bz2
c-common.c (empty_if_body_warning): Remove.
2008-09-30 Paolo Bonzini <bonzini@gnu.org> * c-common.c (empty_if_body_warning): Remove. * c-common.h (empty_if_body_warning): Remove. * c-parser.c (c_parser_if_body, c_parser_else_body): Implement here the -Wempty-body warning for `if' and `else' statements. * c-typeck.c (c_finish_if_stmt): Do not call empty_body_warning. cp: 2008-09-30 Paolo Bonzini <bonzini@gnu.org> * parser.c (cp_parser_selection_statement): Implement here the -Wempty-body warning for `if' and `else' statements. * semantics.c (finish_if_stmt): Do not call empty_body_warning. testsuite: 2008-09-30 Paolo Bonzini <bonzini@gnu.org> * g++.dg/warn/if-empty-1.C: Copy from gcc.dg/if-empty-1.c. From-SVN: r140780
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-common.c25
-rw-r--r--gcc/c-common.h1
-rw-r--r--gcc/c-parser.c7
-rw-r--r--gcc/c-typeck.c2
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c24
-rw-r--r--gcc/cp/semantics.c1
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/warn/if-empty-1.C23
10 files changed, 70 insertions, 31 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5a9b482..68de57a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2008-09-30 Paolo Bonzini <bonzini@gnu.org>
+
+ * c-common.c (empty_if_body_warning): Remove.
+ * c-common.h (empty_if_body_warning): Remove.
+ * c-parser.c (c_parser_if_body, c_parser_else_body): Implement
+ here the -Wempty-body warning for `if' and `else' statements.
+ * c-typeck.c (c_finish_if_stmt): Do not call empty_body_warning.
+
2008-09-29 H.J. Lu <hongjiu.lu@intel.com>
* config/i386/i386.opt: Add msse2avx.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 5d69211..7665b62 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -1291,31 +1291,6 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
return false;
}
-/* Print a warning about if (); or if () .. else; constructs
- via the special empty statement node that we create. INNER_THEN
- and INNER_ELSE are the statement lists of the if and the else
- block. */
-
-void
-empty_if_body_warning (tree inner_then, tree inner_else)
-{
- 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 (IS_EMPTY_STMT (inner_then) && !inner_else)
- warning (OPT_Wempty_body, "%Hsuggest braces around empty body "
- "in an %<if%> statement", EXPR_LOCUS (inner_then));
-
- 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
of `main'. */
diff --git a/gcc/c-common.h b/gcc/c-common.h
index 15ea573..622100a 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -726,7 +726,6 @@ struct varray_head_tag;
extern void constant_expression_warning (tree);
extern void constant_expression_error (tree);
extern bool strict_aliasing_warning (tree, tree, tree);
-extern void empty_if_body_warning (tree, tree);
extern void warnings_for_convert_and_check (tree, tree, tree);
extern tree convert_and_check (tree, tree);
extern void overflow_warning (tree);
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 2b64c86..9597660 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -3858,8 +3858,12 @@ c_parser_if_body (c_parser *parser, bool *if_p)
*if_p = c_parser_next_token_is_keyword (parser, RID_IF);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
+ location_t loc = c_parser_peek_token (parser)->location;
add_stmt (build_empty_stmt ());
c_parser_consume_token (parser);
+ if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
+ warning_at (loc, OPT_Wempty_body,
+ "suggest braces around empty body in an %<if%> statement");
}
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
add_stmt (c_parser_compound_statement (parser));
@@ -3883,6 +3887,9 @@ c_parser_else_body (c_parser *parser)
c_parser_label (parser);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
+ warning_at (c_parser_peek_token (parser)->location,
+ OPT_Wempty_body,
+ "suggest braces around empty body in an %<else%> statement");
add_stmt (build_empty_stmt ());
c_parser_consume_token (parser);
}
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 1424405..c6474ed 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -7440,8 +7440,6 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
&if_locus);
}
- 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);
add_stmt (stmt);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8c722d8..5e5c742 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2008-09-30 Paolo Bonzini <bonzini@gnu.org>
+
+ * parser.c (cp_parser_selection_statement): Implement here the
+ -Wempty-body warning for `if' and `else' statements.
+ * semantics.c (finish_if_stmt): Do not call empty_body_warning.
+
2008-09-25 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/37649
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f28c76d..c368a1c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7155,7 +7155,17 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p)
/* Parse the then-clause. */
in_statement = parser->in_statement;
parser->in_statement |= IN_IF_STMT;
- cp_parser_implicitly_scoped_statement (parser, &nested_if);
+ if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
+ {
+ location_t loc = cp_lexer_peek_token (parser->lexer)->location;
+ add_stmt (build_empty_stmt ());
+ cp_lexer_consume_token (parser->lexer);
+ if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_ELSE))
+ warning_at (loc, OPT_Wempty_body, "suggest braces around "
+ "empty body in an %<if%> statement");
+ }
+ else
+ cp_parser_implicitly_scoped_statement (parser, &nested_if);
parser->in_statement = in_statement;
finish_then_clause (statement);
@@ -7168,7 +7178,17 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p)
cp_lexer_consume_token (parser->lexer);
begin_else_clause (statement);
/* Parse the else-clause. */
- cp_parser_implicitly_scoped_statement (parser, NULL);
+ if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
+ {
+ warning_at (cp_lexer_peek_token (parser->lexer)->location,
+ OPT_Wempty_body, "suggest braces around "
+ "empty body in an %<else%> statement");
+ add_stmt (build_empty_stmt ());
+ cp_lexer_consume_token (parser->lexer);
+ }
+ else
+ cp_parser_implicitly_scoped_statement (parser, NULL);
+
finish_else_clause (statement);
/* If we are currently parsing a then-clause, then
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 176a7fd..13e9a0f 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -695,7 +695,6 @@ finish_if_stmt (tree if_stmt)
TREE_CHAIN (if_stmt) = NULL;
add_stmt (do_poplevel (scope));
finish_stmt ();
- empty_if_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
}
/* Begin a while-statement. Returns a newly created WHILE_STMT if
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index df91766..28086b3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2008-09-30 Paolo Bonzini <bonzini@gnu.org>
+ * g++.dg/warn/if-empty-1.C: Copy from gcc.dg/if-empty-1.c.
+
+2008-09-30 Paolo Bonzini <bonzini@gnu.org>
+
PR testsuite/36891
PR testsuite/37675
* gcc.dg/torture/pr36891.c: Add -msse on 32-bit i386.
diff --git a/gcc/testsuite/g++.dg/warn/if-empty-1.C b/gcc/testsuite/g++.dg/warn/if-empty-1.C
new file mode 100644
index 0000000..b29a6cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/if-empty-1.C
@@ -0,0 +1,23 @@
+/* Test diagnostics for empty bodies in if / else. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wempty-body" } */
+
+void
+f (int x)
+{
+ if (x)
+ ; /* { dg-warning "suggest braces around empty body in an" } */
+ if (x)
+ ; /* By design we don't warn in this case. */
+ else
+ (void)0;
+ if (x)
+ (void)0;
+ else
+ ; /* { dg-warning "suggest braces around empty body in an" } */
+ if (x)
+ (void)0;
+ else
+ (void)0;
+}