This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Revert -Wempty-body C++ for/while warning (PR c++/36478)


On Wed, Nov 12, 2008 at 10:15:48AM -0800, Mark Mitchell wrote:
> Jakub Jelinek wrote:
> > Fine with my, should I prepare a patch?
> 
> Yes, I think that's probably the thing to do.
> 
> I think that Mike's patch is too closely tied to the coding conventions
> of particular users.  If we're going to warn about this at all (and I
> think we should), we should do so independent of the exact use of
> whitespace and such.
> 
> I believe that Lint had special comments to disable certain warnings.
> If we want, we could have comments/pragmas/etc. that users could use to
> explicitly disable this warning.

Here it is then, bootstrapped/regtested on x86_64-linux.  Ok for trunk?

2008-11-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/36478
	Revert:
	2007-05-07  Mike Stump  <mrs@apple.com>
	* doc/invoke.texi (Warning Options): Document that -Wempty-body
	also checks for and while statements in C++.

	Revert:
	2007-05-07  Mike Stump  <mrs@apple.com>
	* parser.c (check_empty_body): Add.
	(cp_parser_iteration_statement): Add call to check_empty_body.

	* g++.old-deja/g++.mike/empty.C: Remove.

--- gcc/cp/parser.c.jj	2008-11-12 13:33:02.000000000 +0100
+++ gcc/cp/parser.c	2008-11-12 20:38:34.000000000 +0100
@@ -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
 	/* 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
 	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, "%<)%>");
 
--- gcc/doc/invoke.texi.jj	2008-10-23 09:07:05.000000000 +0200
+++ gcc/doc/invoke.texi	2008-11-12 20:39:30.000000000 +0100
@@ -3678,9 +3678,7 @@ integers are disabled by default in C++ 
 @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
--- gcc/testsuite/g++.old-deja/g++.mike/empty.C.jj	2008-09-30 16:55:03.000000000 +0200
+++ gcc/testsuite/g++.old-deja/g++.mike/empty.C	2008-11-12 20:40:46.000000000 +0100
@@ -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;
-}


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]