It's now possible to see an active member of a union that has not actually
been initialized, so let's clarify the diagnostic.
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_component_reference): Clarify diagnostic.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-98122.C: Adjust diagnostic.
* g++.dg/cpp26/constexpr-new6a.C: New test.
if (cep->value == NULL_TREE)
error ("accessing uninitialized member %qD", part);
else
- error ("accessing %qD member instead of initialized %qD member "
+ error ("accessing %qD member instead of active %qD member "
"in constant expression", part, cep->index);
}
*non_constant_p = true;
--- /dev/null
+// { dg-do compile { target c++26 } }
+
+#include <new>
+
+union U { double d; int i; };
+
+constexpr int f()
+{
+ U u;
+ new (&u.i) int;
+ return u.d; // { dg-error "active" }
+}
+
+int main ()
+{
+ constexpr int i = f(); // { dg-message "" }
+}
{
V f { .b = 42 };
constexpr auto m = &V::a;
- return (f.*m) == 42; // { dg-error "accessing 'V::a' member instead of initialized 'V::b' member in constant expression" }
+ return (f.*m) == 42; // { dg-error "accessing 'V::a' member instead of active 'V::b' member in constant expression" }
}
constexpr bool