* constexpr.c (cxx_eval_store_expression): A store to a union member
erases a previous store to another member.
From-SVN: r245341
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.
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))
--- /dev/null
+// PR c++/78897
+// { dg-do compile { target c++14 } }
+
+struct Optional {
+ constexpr Optional() : _dummy{} { _value = 1; }
+ union {
+ int _dummy;
+ int _value;
+ };
+};
+Optional opt{};