diff options
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 2a7c1e7..60035ea 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). */ |