diff options
author | Paolo Bonzini <bonzini@gnu.org> | 2008-09-30 09:52:41 +0000 |
---|---|---|
committer | Paolo Bonzini <bonzini@gcc.gnu.org> | 2008-09-30 09:52:41 +0000 |
commit | 626c34b5c945cc9c577bd0509d297b81df083d3f (patch) | |
tree | 550e5d90532796178dbba4eb2e6ff1c54828d12c /gcc/cp | |
parent | b5d60b839fd858c794384f4e6bf18005211e7add (diff) | |
download | gcc-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/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 24 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 1 |
3 files changed, 28 insertions, 3 deletions
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 |