diff options
author | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-06-03 17:35:34 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-06-03 17:35:34 +0000 |
commit | fedfecef5e3e78daf0d970d8edb4ab33a167535c (patch) | |
tree | 91bf428ee9f7a6bf677d0b5faa7d6cf778b29135 /gcc/cp/semantics.c | |
parent | e4f36438a9dd49f88a9fb4006b481aeeda780255 (diff) | |
download | gcc-fedfecef5e3e78daf0d970d8edb4ab33a167535c.zip gcc-fedfecef5e3e78daf0d970d8edb4ab33a167535c.tar.gz gcc-fedfecef5e3e78daf0d970d8edb4ab33a167535c.tar.bz2 |
re PR c/60439 (No warning for case overflow in switch statement.)
PR c/60439
* doc/invoke.texi: Document -Wswitch-bool.
* function.c (stack_protect_epilogue): Cast controlling expression of
the switch to int.
* gengtype.c (walk_type): Generate switch expression with its
controlling expression cast to int.
c/
* c-parser.c (c_parser_switch_statement): Pass explicit_cast_p to
c_start_case.
* c-tree.h (c_start_case): Update.
* c-typeck.c (c_start_case): Add new boolean parameter. Warn if
switch condition has boolean value.
cp/
* semantics.c (finish_switch_cond): Warn if switch condition has
boolean value.
c-family/
* c.opt (Wswitch-bool): New option.
testsuite/
* c-c++-common/pr60439.c: New test.
* g++.dg/eh/scope1.C (f4): Add dg-warning.
From-SVN: r211194
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r-- | gcc/cp/semantics.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 21920b4..c1c16f4 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1130,6 +1130,11 @@ finish_switch_cond (tree cond, tree switch_stmt) orig_type = TREE_TYPE (cond); if (cond != error_mark_node) { + /* Warn if the condition has boolean value. */ + if (TREE_CODE (orig_type) == BOOLEAN_TYPE) + warning_at (input_location, OPT_Wswitch_bool, + "switch condition has type bool"); + /* [stmt.switch] Integral promotions are performed. */ |