From 74ac79fa800af6de648e984cc5576c20b817839d Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Fri, 20 Jan 2006 09:30:22 +0000 Subject: re PR c++/5520 (Add a warning to detect empty body of if statements (like in the C frontend)) 2006-01-20 Dirk Mueller 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 --- gcc/cp/parser.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'gcc/cp/parser.c') 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; -- cgit v1.1