* decl.c (reshape_init_r): Don't reshape a digested initializer.
Return the initializer for COMPOUND_LITERAL_P.
+ PR c++/88983 - ICE with switch in constexpr function.
+ * constexpr.c (cxx_eval_switch_expr): Use SWITCH_COND and SWITCH_BODY.
+ (cxx_eval_constant_expression) <case COND_EXPR>: Don't look for the
+ label in the else branch if we found it in the then branch.
+
2019-01-30 Jason Merrill <jason@redhat.com>
PR c++/88752 - ICE with lambda and constexpr if.
bool *non_constant_p, bool *overflow_p,
tree *jump_target)
{
- tree cond = TREE_OPERAND (t, 0);
+ tree cond = SWITCH_COND (t);
cond = cxx_eval_constant_expression (ctx, cond, false,
non_constant_p, overflow_p);
VERIFY_CONSTANT (cond);
*jump_target = cond;
- tree body = TREE_OPERAND (t, 1);
+ tree body = SWITCH_BODY (t);
constexpr_ctx new_ctx = *ctx;
constexpr_switch_state css = css_default_not_seen;
new_ctx.css_state = &css;
case COND_EXPR:
if (jump_target && *jump_target)
{
+ tree orig_jump = *jump_target;
/* When jumping to a label, the label might be either in the
then or else blocks, so process then block first in skipping
mode first, and if we are still in the skipping mode at its end,
r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1),
lval, non_constant_p, overflow_p,
jump_target);
- if (*jump_target)
+ /* It's possible that we found the label in the then block. But
+ it could have been followed by another jumping statement, e.g.
+ say we're looking for case 1:
+ if (cond)
+ {
+ // skipped statements
+ case 1:; // clears up *jump_target
+ return 1; // and sets it to a RETURN_EXPR
+ }
+ else { ... }
+ in which case we need not go looking to the else block.
+ (goto is not allowed in a constexpr function.) */
+ if (*jump_target == orig_jump)
r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 2),
lval, non_constant_p, overflow_p,
jump_target);