diff options
author | Dirk Mueller <dmueller@suse.com> | 2006-01-20 09:30:22 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2006-01-20 09:30:22 +0000 |
commit | 74ac79fa800af6de648e984cc5576c20b817839d (patch) | |
tree | bc92b7d88bae96e3177ed2217eb031fe56a30961 /gcc/cp/parser.c | |
parent | 577b02d86397e9f5a09392d2ea9f722b8a250709 (diff) | |
download | gcc-74ac79fa800af6de648e984cc5576c20b817839d.zip gcc-74ac79fa800af6de648e984cc5576c20b817839d.tar.gz gcc-74ac79fa800af6de648e984cc5576c20b817839d.tar.bz2 |
re PR c++/5520 (Add a warning to detect empty body of if statements (like in the C frontend))
2006-01-20 Dirk Mueller <dmueller@suse.com>
PR c++/5520
* c-parser.c (c_parser_if_body): Use build_empty_stmt()
instead of a special NOP marker.
* c-typeck.c (c_finish_if_stmt): Remove obsoleted special
NOP marker handling.
* c-common.h (empty_body_warning): Add forward declaration.
* c-common.c (empty_body_warning): Add (from c_finish_if_stmt).
Now uses IS_EMPTY_STMT() instead of special NOP markers.
* semantics.c (finish_if_stmt): Call empty_body_warning.
* parser.c (cp_parser_implicitly_scoped_statement):
Mark empty statement with an empty stmt.
* g++.dg/warn/empty-body.C: New.
From-SVN: r110019
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d2b41e5..cf19fbf 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6827,8 +6827,17 @@ cp_parser_implicitly_scoped_statement (cp_parser* parser) { tree statement; + /* Mark if () ; with a special NOP_EXPR. */ + if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) + { + cp_lexer_consume_token (parser->lexer); + statement = add_stmt (build_empty_stmt ()); + } + /* if a compound is opened, we simply parse the statement directly. */ + else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) + statement = cp_parser_compound_statement (parser, NULL, false); /* If the token is not a `{', then we must take special action. */ - if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE)) + else { /* Create a compound-statement. */ statement = begin_compound_stmt (0); @@ -6837,9 +6846,6 @@ cp_parser_implicitly_scoped_statement (cp_parser* parser) /* Finish the dummy compound-statement. */ finish_compound_stmt (statement); } - /* Otherwise, we simply parse the statement directly. */ - else - statement = cp_parser_compound_statement (parser, NULL, false); /* Return the statement. */ return statement; |