Here we have one empty subobject inside another; we didn't create a
CONSTRUCTOR for the outer one, so we don't have it as context for the inner.
PR c++/125315
gcc/cp/ChangeLog:
* constexpr.cc (init_subob_ctx): Allow both ctor and object
to be null for an empty subobject.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/no_unique_address16.C: New test.
else if (ctx->object)
ctxtype = TREE_TYPE (ctx->object);
else
- gcc_unreachable ();
+ {
+ /* This can happen if the enclosing object is also an empty subobject
+ (c++/125315). */
+ gcc_checking_assert (is_empty_class (type));
+ return;
+ }
if (VECTOR_TYPE_P (type)
&& VECTOR_TYPE_P (ctxtype)
--- /dev/null
+// PR c++/125315
+// { dg-do compile { target c++20 } }
+// { dg-prune-output "used but never defined" }
+
+struct S{~S(){}};
+constexpr S& f(S& t);
+struct W{[[no_unique_address]]S v;};
+struct R:W{};
+S s;
+auto x=R{{f(s)}};