The change of active member being non-constant (before C++20) results in a
CONSTRUCTOR with a null value for the first field, don't crash.
gcc/cp/ChangeLog:
* constexpr.cc (free_constructor): Handle null ce->value.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-union7.C: New test.
{
constructor_elt *ce;
for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
- if (TREE_CODE (ce->value) == CONSTRUCTOR)
+ if (ce->value && TREE_CODE (ce->value) == CONSTRUCTOR)
vec_safe_push (ctors, ce->value);
ggc_free (elts);
}
--- /dev/null
+// { dg-do compile { target c++14 } }
+// { dg-options "" }
+
+union U { int i; float f; };
+constexpr auto g (U u) { return (u.i = 42); } // { dg-error "active member" "" { target c++17_down } }
+static_assert (g({.f = 3.14}) == 42); // { dg-error "non-constant" "" { target c++17_down } }