invoke.texi (Warning Options): Document that -Wempty-body also checks for and while statements in C++.
* doc/invoke.texi (Warning Options): Document that -Wempty-body also checks for and while statements in C++. cp: * parser.c (check_empty_body): Add. (cp_parser_iteration_statement): Add call to check_empty_body. testsuite: * g++.old-deja/g++.mike/empty.C: Add. From-SVN: r124534
This commit is contained in:
parent
79d37e4574
commit
841cc7daf3
|
@ -1,3 +1,8 @@
|
||||||
|
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++.
|
||||||
|
|
||||||
2007-05-07 Nathan Froyd <froydnj@codesourcery.com>
|
2007-05-07 Nathan Froyd <froydnj@codesourcery.com>
|
||||||
|
|
||||||
* gcc.c (at_file_supplied): New variable.
|
* gcc.c (at_file_supplied): New variable.
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2007-05-07 Mike Stump <mrs@apple.com>
|
||||||
|
|
||||||
|
* parser.c (check_empty_body): Add.
|
||||||
|
(cp_parser_iteration_statement): Add call to check_empty_body.
|
||||||
|
|
||||||
2007-05-05 Geoffrey Keating <geoffk@apple.com>
|
2007-05-05 Geoffrey Keating <geoffk@apple.com>
|
||||||
|
|
||||||
PR 31775
|
PR 31775
|
||||||
|
|
|
@ -7065,6 +7065,51 @@ cp_parser_condition (cp_parser* parser)
|
||||||
return cp_parser_expression (parser, /*cast_p=*/false);
|
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
|
||||||
|
#ifdef USE_MAPPED_LOCATION
|
||||||
|
&& close_loc.column+1 == semi_loc.column
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
warning (OPT_Wempty_body,
|
||||||
|
"suggest a space before %<;%> or explicit braces around empty "
|
||||||
|
"body in %<%s%> statement",
|
||||||
|
type);
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse an iteration-statement.
|
/* Parse an iteration-statement.
|
||||||
|
|
||||||
iteration-statement:
|
iteration-statement:
|
||||||
|
@ -7107,6 +7152,7 @@ cp_parser_iteration_statement (cp_parser* parser)
|
||||||
/* Parse the condition. */
|
/* Parse the condition. */
|
||||||
condition = cp_parser_condition (parser);
|
condition = cp_parser_condition (parser);
|
||||||
finish_while_stmt_cond (condition, statement);
|
finish_while_stmt_cond (condition, statement);
|
||||||
|
check_empty_body (parser, "while");
|
||||||
/* Look for the `)'. */
|
/* Look for the `)'. */
|
||||||
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
|
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
|
||||||
/* Parse the dependent statement. */
|
/* Parse the dependent statement. */
|
||||||
|
@ -7168,6 +7214,7 @@ cp_parser_iteration_statement (cp_parser* parser)
|
||||||
if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
|
if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
|
||||||
expression = cp_parser_expression (parser, /*cast_p=*/false);
|
expression = cp_parser_expression (parser, /*cast_p=*/false);
|
||||||
finish_for_expr (expression, statement);
|
finish_for_expr (expression, statement);
|
||||||
|
check_empty_body (parser, "for");
|
||||||
/* Look for the `)'. */
|
/* Look for the `)'. */
|
||||||
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
|
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
|
||||||
|
|
||||||
|
|
|
@ -3157,6 +3157,11 @@ An empty body occurs in an @samp{if}, @samp{else} or
|
||||||
@samp{do while} statement. This warning can be independently
|
@samp{do while} statement. This warning can be independently
|
||||||
controlled by @option{-Wempty-body}.
|
controlled by @option{-Wempty-body}.
|
||||||
|
|
||||||
|
@item @r{(C++ only)}
|
||||||
|
An empty body occurs in a @samp{while} or @samp{for} statement with no
|
||||||
|
whitespacing before the semicolon. This warning can be independently
|
||||||
|
controlled by @option{-Wempty-body}.
|
||||||
|
|
||||||
@item
|
@item
|
||||||
A pointer is compared against integer zero with @samp{<}, @samp{<=},
|
A pointer is compared against integer zero with @samp{<}, @samp{<=},
|
||||||
@samp{>}, or @samp{>=}.
|
@samp{>}, or @samp{>=}.
|
||||||
|
@ -3421,8 +3426,10 @@ to them.
|
||||||
|
|
||||||
@item -Wempty-body
|
@item -Wempty-body
|
||||||
@opindex Wempty-body
|
@opindex Wempty-body
|
||||||
An empty body occurs in an @samp{if}, @samp{else} or @samp{do while}
|
Warn if an empty body occurs in an @samp{if}, @samp{else} or @samp{do
|
||||||
statement. This warning is also enabled by @option{-Wextra}.
|
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}.
|
||||||
|
|
||||||
@item -Wsign-compare
|
@item -Wsign-compare
|
||||||
@opindex Wsign-compare
|
@opindex Wsign-compare
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
2007-05-07 Mike Stump <mrs@apple.com>
|
||||||
|
|
||||||
|
* g++.old-deja/g++.mike/empty.C: Add.
|
||||||
|
|
||||||
2007-05-07 Eric Christopher <echristo@apple.com>
|
2007-05-07 Eric Christopher <echristo@apple.com>
|
||||||
|
|
||||||
* gcc.dg/invalid-call-1.c: Fix options for 32-bit x86.
|
* gcc.dg/invalid-call-1.c: Fix options for 32-bit x86.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
// { dg-options "-W" }
|
||||||
|
|
||||||
|
#define NOPE
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
while (1); /* { dg-error "suggest a space before " } */
|
||||||
|
{
|
||||||
|
}
|
||||||
|
for (;;); /* { dg-error "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" { xfail *-*-* } } */
|
||||||
|
for (;;) NOPE; /* { dg-bogus "suggest a space before " "suggest" { xfail *-*-* } } */
|
||||||
|
while (1)
|
||||||
|
NOPE;
|
||||||
|
for (;;)
|
||||||
|
NOPE;
|
||||||
|
}
|
Loading…
Reference in New Issue