mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-27 04:55:01 +08:00
c-common.h (empty_body_warning): Rename to empty_if_body_warning.
2007-03-14 Dirk Mueller <dmueller@suse.de> * c-common.h (empty_body_warning): Rename to empty_if_body_warning. * c-common.c (empty_if_body_warning): Rephrase diagnostic message. * c-parser.c (c_parser_if_body): Always add an empty statement in case of empty body. * c-parser.c (c_parser_do_statement): Warn about empty body in do/while statement. * c-typeck (c_finish_if_stmt): Call empty_if_body_warning. * doc/invoke.texi (-Wempty-body): Update documentation. * cp/semantics.c (c_finish_if_stmt): Call empty_if_body_warning. (finish_do_body): Warn about empty body in do/while statement. * g++.dg/warn/do-empty.C: New. * gcc.dg/do-empty.c: New. * gcc.dg/if-empty-1.c: Update. * gcc.dg/20001116-1.c: Update. * gcc.dg/pr23165.c: Update. From-SVN: r122928
This commit is contained in:
parent
adea5e16e4
commit
62e00e9474
@ -1,3 +1,14 @@
|
||||
2007-03-14 Dirk Mueller <dmueller@suse.de>
|
||||
|
||||
* c-common.h (empty_body_warning): Rename to empty_if_body_warning.
|
||||
* c-common.c (empty_if_body_warning): Rephrase diagnostic message.
|
||||
* c-parser.c (c_parser_if_body): Always add an empty statement in case
|
||||
of empty body.
|
||||
* c-parser.c (c_parser_do_statement): Warn about empty body in
|
||||
do/while statement.
|
||||
* c-typeck (c_finish_if_stmt): Call empty_if_body_warning.
|
||||
* doc/invoke.texi (-Wempty-body): Update documentation.
|
||||
|
||||
2007-03-14 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
|
||||
|
||||
PR c/21438
|
||||
|
@ -1056,26 +1056,23 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
|
||||
block. */
|
||||
|
||||
void
|
||||
empty_body_warning (tree inner_then, tree inner_else)
|
||||
empty_if_body_warning (tree inner_then, tree inner_else)
|
||||
{
|
||||
if (warn_empty_body)
|
||||
{
|
||||
if (TREE_CODE (inner_then) == STATEMENT_LIST
|
||||
&& STATEMENT_LIST_TAIL (inner_then))
|
||||
inner_then = STATEMENT_LIST_TAIL (inner_then)->stmt;
|
||||
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 (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, "%Hempty body in an if-statement",
|
||||
EXPR_LOCUS (inner_then));
|
||||
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));
|
||||
|
||||
if (inner_else && IS_EMPTY_STMT (inner_else))
|
||||
warning (OPT_Wempty_body, "%Hempty body in an else-statement",
|
||||
EXPR_LOCUS (inner_else));
|
||||
}
|
||||
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
|
||||
|
@ -670,7 +670,7 @@ extern tree fix_string_type (tree);
|
||||
struct varray_head_tag;
|
||||
extern void constant_expression_warning (tree);
|
||||
extern void strict_aliasing_warning (tree, tree, tree);
|
||||
extern void empty_body_warning (tree, tree);
|
||||
extern void empty_if_body_warning (tree, tree);
|
||||
extern tree convert_and_check (tree, tree);
|
||||
extern void overflow_warning (tree);
|
||||
extern void warn_logical_operator (enum tree_code, tree, tree);
|
||||
|
@ -3844,7 +3844,7 @@ c_parser_if_body (c_parser *parser, bool *if_p)
|
||||
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
|
||||
c_parser_label (parser);
|
||||
*if_p = c_parser_next_token_is_keyword (parser, RID_IF);
|
||||
if (warn_empty_body && c_parser_next_token_is (parser, CPP_SEMICOLON))
|
||||
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
||||
add_stmt (build_empty_stmt ());
|
||||
c_parser_statement_after_labels (parser);
|
||||
return c_end_compound_stmt (block, flag_isoc99);
|
||||
@ -3953,6 +3953,9 @@ c_parser_do_statement (c_parser *parser)
|
||||
location_t loc;
|
||||
gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
|
||||
c_parser_consume_token (parser);
|
||||
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
||||
warning (OPT_Wempty_body,
|
||||
"suggest braces around empty body in %<do%> statement");
|
||||
block = c_begin_compound_stmt (flag_isoc99);
|
||||
loc = c_parser_peek_token (parser)->location;
|
||||
save_break = c_break_label;
|
||||
|
@ -7229,7 +7229,7 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
|
||||
&if_locus);
|
||||
}
|
||||
|
||||
empty_body_warning (then_block, else_block);
|
||||
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);
|
||||
|
@ -1,3 +1,8 @@
|
||||
2007-03-14 Dirk Mueller <dmueller@suse.de>
|
||||
|
||||
* cp/semantics.c (c_finish_if_stmt): Call empty_if_body_warning.
|
||||
(finish_do_body): Warn about empty body in do/while statement.
|
||||
|
||||
2007-03-14 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
|
||||
|
||||
* class.c (warn_hidden): Add OPT_Woverloaded_virtual to warning.
|
||||
|
@ -701,7 +701,7 @@ finish_if_stmt (tree if_stmt)
|
||||
TREE_CHAIN (if_stmt) = NULL;
|
||||
add_stmt (do_poplevel (scope));
|
||||
finish_stmt ();
|
||||
empty_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
|
||||
empty_if_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
|
||||
}
|
||||
|
||||
/* Begin a while-statement. Returns a newly created WHILE_STMT if
|
||||
@ -754,7 +754,14 @@ begin_do_stmt (void)
|
||||
void
|
||||
finish_do_body (tree do_stmt)
|
||||
{
|
||||
DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
|
||||
tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
|
||||
|
||||
if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
|
||||
body = STATEMENT_LIST_TAIL (body)->stmt;
|
||||
|
||||
if (IS_EMPTY_STMT (body))
|
||||
warning (OPT_Wempty_body,
|
||||
"suggest explicit braces around empty body in %<do%> statement");
|
||||
}
|
||||
|
||||
/* Finish a do-statement, which may be given by DO_STMT, and whose
|
||||
|
@ -3136,8 +3136,9 @@ functions. This warning can be independently controlled by
|
||||
@option{-Wmissing-parameter-type}.
|
||||
|
||||
@item
|
||||
An empty body occurs in an @samp{if} or @samp{else} statement. This
|
||||
warning can be independently controlled by @option{-Wempty-body}.
|
||||
An empty body occurs in an @samp{if}, @samp{else} or
|
||||
@samp{do while} statement. This warning can be independently
|
||||
controlled by @option{-Wempty-body}.
|
||||
|
||||
@item
|
||||
A pointer is compared against integer zero with @samp{<}, @samp{<=},
|
||||
@ -3397,8 +3398,8 @@ changed by the conversion like in @code{abs (2.0)}.
|
||||
|
||||
@item -Wempty-body
|
||||
@opindex Wempty-body
|
||||
An empty body occurs in an @samp{if} or @samp{else} statement.
|
||||
This warning is also enabled by @option{-Wextra}.
|
||||
An empty body occurs in an @samp{if}, @samp{else} or @samp{do while}
|
||||
statement. This warning is also enabled by @option{-Wextra}.
|
||||
|
||||
@item -Wsign-compare
|
||||
@opindex Wsign-compare
|
||||
|
@ -1,3 +1,11 @@
|
||||
2007-03-14 Dirk Mueller <dmueller@suse.de>
|
||||
|
||||
* g++.dg/warn/do-empty.C: New.
|
||||
* gcc.dg/do-empty.c: New.
|
||||
* gcc.dg/if-empty-1.c: Update.
|
||||
* gcc.dg/20001116-1.c: Update.
|
||||
* gcc.dg/pr23165.c: Update.
|
||||
|
||||
2007-03-14 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* gfortran.dg/module_implicit_conversion.f90: New test.
|
||||
|
15
gcc/testsuite/g++.dg/warn/do-empty.C
Normal file
15
gcc/testsuite/g++.dg/warn/do-empty.C
Normal file
@ -0,0 +1,15 @@
|
||||
/* Test diagnostics for empty bodies in do / while. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wempty-body" } */
|
||||
|
||||
void
|
||||
f (int x)
|
||||
{
|
||||
do
|
||||
; /* { dg-warning "empty body in" } */
|
||||
while (x--);
|
||||
|
||||
do
|
||||
{} /* { dg-bogus "empty body in" } */
|
||||
while (++x < 10);
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
void foo (int x)
|
||||
{
|
||||
if (x)
|
||||
; /* { dg-warning "empty body in an if-statement" } */
|
||||
; /* { dg-warning "empty body in an" } */
|
||||
}
|
||||
|
15
gcc/testsuite/gcc.dg/do-empty.c
Normal file
15
gcc/testsuite/gcc.dg/do-empty.c
Normal file
@ -0,0 +1,15 @@
|
||||
/* Test diagnostics for empty bodies in do / while. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wempty-body" } */
|
||||
|
||||
void
|
||||
f (int x)
|
||||
{
|
||||
do
|
||||
; /* { dg-warning "empty body in" } */
|
||||
while (x--);
|
||||
|
||||
do
|
||||
{} /* { dg-bogus "empty body in" } */
|
||||
while (++x < 10);
|
||||
}
|
@ -7,7 +7,7 @@ void
|
||||
f (int x)
|
||||
{
|
||||
if (x)
|
||||
; /* { dg-warning "warning: empty body in an if-statement" } */
|
||||
; /* { dg-warning "warning: empty body in an" } */
|
||||
if (x)
|
||||
; /* By design we don't warn in this case. */
|
||||
else
|
||||
@ -15,7 +15,7 @@ f (int x)
|
||||
if (x)
|
||||
(void)0;
|
||||
else
|
||||
; /* { dg-warning "warning: empty body in an else-statement" } */
|
||||
; /* { dg-warning "warning: empty body in an" } */
|
||||
if (x)
|
||||
(void)0;
|
||||
else
|
||||
|
@ -3,7 +3,7 @@
|
||||
void foo (void)
|
||||
{
|
||||
if (0)
|
||||
a: ; /* { dg-warning "empty body in an if-statement" } */
|
||||
a: ; /* { dg-warning "empty body in an" } */
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user