diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-01-20 09:30:22 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-01-20 09:30:22 +0000 |
commit | 50247dd938763df581825bd0d2a09fc39fbe8d85 (patch) | |
tree | bc92b7d88bae96e3177ed2217eb031fe56a30961 /gcc/c-common.c | |
parent | bbb1e488ddd263ca6a4fa4f50ff5b545846e20ec (diff) | |
download | ppe42-gcc-50247dd938763df581825bd0d2a09fc39fbe8d85.tar.gz ppe42-gcc-50247dd938763df581825bd0d2a09fc39fbe8d85.zip |
2006-01-20 Dirk Mueller <dmueller@suse.com>
PR c++/5520
* c-parser.c (c_parser_if_body): Use build_empty_stmt()
instead of a special NOP marker.
* c-typeck.c (c_finish_if_stmt): Remove obsoleted special
NOP marker handling.
* c-common.h (empty_body_warning): Add forward declaration.
* c-common.c (empty_body_warning): Add (from c_finish_if_stmt).
Now uses IS_EMPTY_STMT() instead of special NOP markers.
* semantics.c (finish_if_stmt): Call empty_body_warning.
* parser.c (cp_parser_implicitly_scoped_statement):
Mark empty statement with an empty stmt.
* g++.dg/warn/empty-body.C: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@110019 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 2a7c1e777d3..60035ea601b 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -994,6 +994,36 @@ strict_aliasing_warning(tree otype, tree type, tree expr) } } + +/* 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_body_warning (tree inner_then, tree inner_else) +{ + if (extra_warnings) + { + 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_Wextra, "%Hempty body in an if-statement", + EXPR_LOCUS (inner_then)); + + if (inner_else && IS_EMPTY_STMT (inner_else)) + warning (OPT_Wextra, "%Hempty body in an else-statement", + EXPR_LOCUS (inner_else)); + } +} + + /* Nonzero if constant C has a value that is permissible for type TYPE (an INTEGER_TYPE). */ |