From 084eb83032ac2d343ac2e7d2b355ac0b12a02659 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 12 Nov 2008 23:18:03 +0100 Subject: [PATCH] re PR c++/36478 (warning not emitted when code expanded from macro) PR c++/36478 Revert: 2007-05-07 Mike Stump * doc/invoke.texi (Warning Options): Document that -Wempty-body also checks for and while statements in C++. Revert: 2007-05-07 Mike Stump * parser.c (check_empty_body): Add. (cp_parser_iteration_statement): Add call to check_empty_body. * g++.old-deja/g++.mike/empty.C: Remove. From-SVN: r141810 --- gcc/ChangeLog | 8 ++++ gcc/cp/ChangeLog | 8 ++++ gcc/cp/parser.c | 44 --------------------- gcc/doc/invoke.texi | 4 +- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.old-deja/g++.mike/empty.C | 25 ------------ 6 files changed, 22 insertions(+), 72 deletions(-) delete mode 100644 gcc/testsuite/g++.old-deja/g++.mike/empty.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2cd719a87ae..f36a6667f3c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2008-11-12 Jakub Jelinek + + PR c++/36478 + Revert: + 2007-05-07 Mike Stump + * doc/invoke.texi (Warning Options): Document that -Wempty-body + also checks for and while statements in C++. + 2008-11-12 Dodji Seketeli PR debug/27574 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 769e4cbc755..0a956d83584 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2008-11-12 Jakub Jelinek + + PR c++/36478 + Revert: + 2007-05-07 Mike Stump + * parser.c (check_empty_body): Add. + (cp_parser_iteration_statement): Add call to check_empty_body. + 2008-11-12 Jason Merrill PR c++/38007 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ec9624e69b2..ba8759c954c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7427,48 +7427,6 @@ cp_parser_condition (cp_parser* parser) return cp_parser_expression (parser, /*cast_p=*/false); } -/* We check for a ) immediately followed by ; with no whitespacing - between. This is used to issue a warning for: - - while (...); - - and: - - for (...); - - as the semicolon is probably extraneous. - - On parse errors, the next token might not be a ), so do nothing in - that case. */ - -static void -check_empty_body (cp_parser* parser, const char* type) -{ - cp_token *token; - cp_token *close_paren; - expanded_location close_loc; - expanded_location semi_loc; - - close_paren = cp_lexer_peek_token (parser->lexer); - if (close_paren->type != CPP_CLOSE_PAREN) - return; - - close_loc = expand_location (close_paren->location); - token = cp_lexer_peek_nth_token (parser->lexer, 2); - - if (token->type != CPP_SEMICOLON - || (token->flags & PREV_WHITE)) - return; - - semi_loc = expand_location (token->location); - if (close_loc.line == semi_loc.line - && close_loc.column+1 == semi_loc.column) - warning (OPT_Wempty_body, - "suggest a space before %<;%> or explicit braces around empty " - "body in %<%s%> statement", - type); -} - /* Parse an iteration-statement. iteration-statement: @@ -7511,7 +7469,6 @@ cp_parser_iteration_statement (cp_parser* parser) /* Parse the condition. */ condition = cp_parser_condition (parser); finish_while_stmt_cond (condition, statement); - check_empty_body (parser, "while"); /* Look for the `)'. */ cp_parser_require (parser, CPP_CLOSE_PAREN, "%<)%>"); /* Parse the dependent statement. */ @@ -7573,7 +7530,6 @@ cp_parser_iteration_statement (cp_parser* parser) if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)) expression = cp_parser_expression (parser, /*cast_p=*/false); finish_for_expr (expression, statement); - check_empty_body (parser, "for"); /* Look for the `)'. */ cp_parser_require (parser, CPP_CLOSE_PAREN, "%<)%>"); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9016949ec96..3f6f400f6dc 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3678,9 +3678,7 @@ integers are disabled by default in C++ unless @opindex Wempty-body @opindex Wno-empty-body Warn if an empty body occurs in an @samp{if}, @samp{else} or @samp{do -while} statement. Additionally, in C++, warn when an empty body occurs -in a @samp{while} or @samp{for} statement with no whitespacing before -the semicolon. This warning is also enabled by @option{-Wextra}. +while} statement. This warning is also enabled by @option{-Wextra}. @item -Wenum-compare @r{(C++ and Objective-C++ only)} @opindex Wenum-compare diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7a07fbda344..74c5006ae5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-11-12 Jakub Jelinek + + PR c++/36478 + * g++.old-deja/g++.mike/empty.C: Remove. + 2008-11-12 Dodji Seketeli PR debug/27574 diff --git a/gcc/testsuite/g++.old-deja/g++.mike/empty.C b/gcc/testsuite/g++.old-deja/g++.mike/empty.C deleted file mode 100644 index c36942e3200..00000000000 --- a/gcc/testsuite/g++.old-deja/g++.mike/empty.C +++ /dev/null @@ -1,25 +0,0 @@ -// { dg-options "-W" } - -#define NOPE - -void foo() { - while (1); /* { dg-warning "suggest a space before " } */ - { - } - for (;;); /* { dg-warning "suggest a space before " } */ - { - } - while (1) - ; - for (;;) - ; - while (1) ; - for (;;) ; - /* These two work when using mapped locations */ - while (1) NOPE; /* { dg-bogus "suggest a space before " "suggest" } */ - for (;;) NOPE; /* { dg-bogus "suggest a space before " "suggest" } */ - while (1) - NOPE; - for (;;) - NOPE; -} -- 2.30.2