Commit 5c97093b by Jason Merrill Committed by Jason Merrill

PR c++/78897 - constexpr union

	* constexpr.c (cxx_eval_store_expression): A store to a union member
	erases a previous store to another member.

From-SVN: r245341
parent f494ac0e
2017-02-10 Jason Merrill <jason@redhat.com>
PR c++/78897 - constexpr union
* constexpr.c (cxx_eval_store_expression): A store to a union member
erases a previous store to another member.
PR c++/71285 - member of fold-expression
* semantics.c (finish_unary_fold_expr)
(finish_binary_fold_expr): Use null type for fold-expressions.
......
......@@ -3466,6 +3466,11 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
tree fields = TYPE_FIELDS (DECL_CONTEXT (index));
unsigned HOST_WIDE_INT idx;
if (code == UNION_TYPE && CONSTRUCTOR_NELTS (*valp)
&& CONSTRUCTOR_ELT (*valp, 0)->index != index)
/* Changing active member. */
vec_safe_truncate (CONSTRUCTOR_ELTS (*valp), 0);
for (idx = 0;
vec_safe_iterate (CONSTRUCTOR_ELTS (*valp), idx, &cep);
idx++, fields = DECL_CHAIN (fields))
......
// PR c++/78897
// { dg-do compile { target c++14 } }
struct Optional {
constexpr Optional() : _dummy{} { _value = 1; }
union {
int _dummy;
int _value;
};
};
Optional opt{};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment