2014-11-18 Jason Merrill <jason@redhat.com>
+ * constexpr.c (cxx_eval_statement_list): Handle statement-expressions.
+ (potential_constant_expression_1): Handle STMT_EXPR.
+
* constexpr.c (cxx_eval_constant_expression): Give jump_target a
default argument.
(lots): Omit NULL jump_target arguments.
{
tree_stmt_iterator i;
tree_stmt_iterator default_label = tree_stmt_iterator();
+ tree local_target;
+ /* In a statement-expression we want to return the last value. */
+ tree r = NULL_TREE;
+ if (!jump_target)
+ {
+ local_target = NULL_TREE;
+ jump_target = &local_target;
+ }
for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
{
reenter:
else
continue;
}
- cxx_eval_constant_expression (ctx, stmt,
- false,
- non_constant_p, overflow_p,
- jump_target);
+ r = cxx_eval_constant_expression (ctx, stmt, false,
+ non_constant_p, overflow_p,
+ jump_target);
if (*non_constant_p)
break;
if (returns (jump_target) || breaks (jump_target))
*jump_target = NULL_TREE;
goto reenter;
}
- return NULL_TREE;
+ return r;
}
/* Evaluate a LOOP_EXPR for side-effects. Handles break and return
return false;
return true;
+ case STMT_EXPR:
+ return potential_constant_expression_1 (STMT_EXPR_STMT (t), rval, flags);
+
case LAMBDA_EXPR:
case DYNAMIC_CAST_EXPR:
case PSEUDO_DTOR_EXPR:
/* GCC internal stuff. */
case VA_ARG_EXPR:
case OBJ_TYPE_REF:
- case STMT_EXPR:
case TRANSACTION_EXPR:
case ASM_EXPR:
fail: