This patch ought to fix a regression introduced by the C++ delayed folding merge. What happens here for this testcase is that in c_add_case_label we convert "0" to NOP_EXPR: "(const A) 0" in convert_and_check. We pass this to check_case_bounds which only expects INTEGER_CSTs. Since we can't use maybe_constant_value or fold_simple, I decided to try to use just fold (but just STRIP_SIGN_NOPS should work as well).
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-11-16 Marek Polacek <pola...@redhat.com> PR c++/68362 * c-common.c (check_case_bounds): Fold low and high cases. * g++.dg/delayedfold/switch-1.C: New test. diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index f8ccb6d..03c90f7 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -3769,6 +3769,10 @@ check_case_bounds (location_t loc, tree type, tree orig_type, min_value = TYPE_MIN_VALUE (orig_type); max_value = TYPE_MAX_VALUE (orig_type); + /* We'll really need integer constants here. */ + case_low = fold (case_low); + case_high = fold (case_high); + /* Case label is less than minimum for type. */ if (tree_int_cst_compare (case_low, min_value) < 0 && tree_int_cst_compare (case_high, min_value) < 0) diff --git gcc/testsuite/g++.dg/delayedfold/switch-1.C gcc/testsuite/g++.dg/delayedfold/switch-1.C index e69de29..302da23 100644 --- gcc/testsuite/g++.dg/delayedfold/switch-1.C +++ gcc/testsuite/g++.dg/delayedfold/switch-1.C @@ -0,0 +1,19 @@ +// PR c++/68362 +// { dg-do compile { target c++11 } } + +enum class A { foo }; +enum E { bar }; + +void +fn1 (const A a) +{ + switch (a) + case A::foo:; +} + +void +fn2 (E e) +{ + switch (e) + case bar:; +} Marek