aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.c
diff options
context:
space:
mode:
authorMarek Polacek <mpolacek@gcc.gnu.org>2014-06-03 17:35:34 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2014-06-03 17:35:34 +0000
commitfedfecef5e3e78daf0d970d8edb4ab33a167535c (patch)
tree91bf428ee9f7a6bf677d0b5faa7d6cf778b29135 /gcc/c/c-parser.c
parente4f36438a9dd49f88a9fb4006b481aeeda780255 (diff)
downloadgcc-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/c/c-parser.c')
-rw-r--r--gcc/c/c-parser.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 1d9780e..abd636c 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -5197,9 +5197,13 @@ c_parser_switch_statement (c_parser *parser)
gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
c_parser_consume_token (parser);
block = c_begin_compound_stmt (flag_isoc99);
+ bool explicit_cast_p = false;
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
{
switch_cond_loc = c_parser_peek_token (parser)->location;
+ if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
+ && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
+ explicit_cast_p = true;
ce = c_parser_expression (parser);
ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false);
expr = ce.value;
@@ -5217,7 +5221,7 @@ c_parser_switch_statement (c_parser *parser)
switch_cond_loc = UNKNOWN_LOCATION;
expr = error_mark_node;
}
- c_start_case (switch_loc, switch_cond_loc, expr);
+ c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
save_break = c_break_label;
c_break_label = NULL_TREE;
body = c_parser_c99_block_statement (parser);