c-common.c (empty_if_body_warning): Remove.

2008-09-30  Paolo Bonzini  <bonzini@gnu.org>

	* c-common.c (empty_if_body_warning): Remove.
	* c-common.h (empty_if_body_warning): Remove.
	* c-parser.c (c_parser_if_body, c_parser_else_body): Implement
	here the -Wempty-body warning for `if' and `else' statements.
	* c-typeck.c (c_finish_if_stmt): Do not call empty_body_warning.

cp:
2008-09-30  Paolo Bonzini  <bonzini@gnu.org>

	* parser.c (cp_parser_selection_statement): Implement here the
	-Wempty-body warning for `if' and `else' statements.
	* semantics.c (finish_if_stmt): Do not call empty_body_warning.

testsuite:
2008-09-30  Paolo Bonzini  <bonzini@gnu.org>

	* g++.dg/warn/if-empty-1.C: Copy from gcc.dg/if-empty-1.c.

From-SVN: r140780
This commit is contained in:
Paolo Bonzini 2008-09-30 09:52:41 +00:00 committed by Paolo Bonzini
parent b5d60b839f
commit 626c34b5c9
10 changed files with 70 additions and 31 deletions

View File

@ -1,3 +1,11 @@
2008-09-30 Paolo Bonzini <bonzini@gnu.org>
* c-common.c (empty_if_body_warning): Remove.
* c-common.h (empty_if_body_warning): Remove.
* c-parser.c (c_parser_if_body, c_parser_else_body): Implement
here the -Wempty-body warning for `if' and `else' statements.
* c-typeck.c (c_finish_if_stmt): Do not call empty_body_warning.
2008-09-29 H.J. Lu <hongjiu.lu@intel.com>
* config/i386/i386.opt: Add msse2avx.

View File

@ -1291,31 +1291,6 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
return false;
}
/* Print a warning about if (); or if () .. else; constructs
via the special empty statement node that we create. INNER_THEN
and INNER_ELSE are the statement lists of the if and the else
block. */
void
empty_if_body_warning (tree inner_then, tree inner_else)
{
if (TREE_CODE (inner_then) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (inner_then))
inner_then = STATEMENT_LIST_TAIL (inner_then)->stmt;
if (inner_else && TREE_CODE (inner_else) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (inner_else))
inner_else = STATEMENT_LIST_TAIL (inner_else)->stmt;
if (IS_EMPTY_STMT (inner_then) && !inner_else)
warning (OPT_Wempty_body, "%Hsuggest braces around empty body "
"in an %<if%> statement", EXPR_LOCUS (inner_then));
else if (inner_else && IS_EMPTY_STMT (inner_else))
warning (OPT_Wempty_body, "%Hsuggest braces around empty body "
"in an %<else%> statement", EXPR_LOCUS (inner_else));
}
/* Warn for unlikely, improbable, or stupid DECL declarations
of `main'. */

View File

@ -726,7 +726,6 @@ struct varray_head_tag;
extern void constant_expression_warning (tree);
extern void constant_expression_error (tree);
extern bool strict_aliasing_warning (tree, tree, tree);
extern void empty_if_body_warning (tree, tree);
extern void warnings_for_convert_and_check (tree, tree, tree);
extern tree convert_and_check (tree, tree);
extern void overflow_warning (tree);

View File

@ -3858,8 +3858,12 @@ c_parser_if_body (c_parser *parser, bool *if_p)
*if_p = c_parser_next_token_is_keyword (parser, RID_IF);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
location_t loc = c_parser_peek_token (parser)->location;
add_stmt (build_empty_stmt ());
c_parser_consume_token (parser);
if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
warning_at (loc, OPT_Wempty_body,
"suggest braces around empty body in an %<if%> statement");
}
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
add_stmt (c_parser_compound_statement (parser));
@ -3883,6 +3887,9 @@ c_parser_else_body (c_parser *parser)
c_parser_label (parser);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
warning_at (c_parser_peek_token (parser)->location,
OPT_Wempty_body,
"suggest braces around empty body in an %<else%> statement");
add_stmt (build_empty_stmt ());
c_parser_consume_token (parser);
}

View File

@ -7440,8 +7440,6 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
&if_locus);
}
empty_if_body_warning (then_block, else_block);
stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
SET_EXPR_LOCATION (stmt, if_locus);
add_stmt (stmt);

View File

@ -1,3 +1,9 @@
2008-09-30 Paolo Bonzini <bonzini@gnu.org>
* parser.c (cp_parser_selection_statement): Implement here the
-Wempty-body warning for `if' and `else' statements.
* semantics.c (finish_if_stmt): Do not call empty_body_warning.
2008-09-25 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/37649

View File

@ -7155,7 +7155,17 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p)
/* Parse the then-clause. */
in_statement = parser->in_statement;
parser->in_statement |= IN_IF_STMT;
cp_parser_implicitly_scoped_statement (parser, &nested_if);
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
{
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
add_stmt (build_empty_stmt ());
cp_lexer_consume_token (parser->lexer);
if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_ELSE))
warning_at (loc, OPT_Wempty_body, "suggest braces around "
"empty body in an %<if%> statement");
}
else
cp_parser_implicitly_scoped_statement (parser, &nested_if);
parser->in_statement = in_statement;
finish_then_clause (statement);
@ -7168,7 +7178,17 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p)
cp_lexer_consume_token (parser->lexer);
begin_else_clause (statement);
/* Parse the else-clause. */
cp_parser_implicitly_scoped_statement (parser, NULL);
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
{
warning_at (cp_lexer_peek_token (parser->lexer)->location,
OPT_Wempty_body, "suggest braces around "
"empty body in an %<else%> statement");
add_stmt (build_empty_stmt ());
cp_lexer_consume_token (parser->lexer);
}
else
cp_parser_implicitly_scoped_statement (parser, NULL);
finish_else_clause (statement);
/* If we are currently parsing a then-clause, then

View File

@ -695,7 +695,6 @@ finish_if_stmt (tree if_stmt)
TREE_CHAIN (if_stmt) = NULL;
add_stmt (do_poplevel (scope));
finish_stmt ();
empty_if_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
}
/* Begin a while-statement. Returns a newly created WHILE_STMT if

View File

@ -1,3 +1,7 @@
2008-09-30 Paolo Bonzini <bonzini@gnu.org>
* g++.dg/warn/if-empty-1.C: Copy from gcc.dg/if-empty-1.c.
2008-09-30 Paolo Bonzini <bonzini@gnu.org>
PR testsuite/36891

View File

@ -0,0 +1,23 @@
/* Test diagnostics for empty bodies in if / else. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wempty-body" } */
void
f (int x)
{
if (x)
; /* { dg-warning "suggest braces around empty body in an" } */
if (x)
; /* By design we don't warn in this case. */
else
(void)0;
if (x)
(void)0;
else
; /* { dg-warning "suggest braces around empty body in an" } */
if (x)
(void)0;
else
(void)0;
}