https://gcc.gnu.org/g:3bcd7855c8fd64282d044684db8b3c7056d7d379
commit r16-8916-g3bcd7855c8fd64282d044684db8b3c7056d7d379 Author: Jason Merrill <[email protected]> Date: Fri May 15 01:15:25 2026 -0400 c++: constexpr nested empty objects [PR125315] 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. (cherry picked from commit 9f42a810e6693a85ed312ca80854733daba75037) Diff: --- gcc/cp/constexpr.cc | 7 ++++++- gcc/testsuite/g++.dg/cpp2a/no_unique_address16.C | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index a593b66dd41b..34863d325267 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -6703,7 +6703,12 @@ init_subob_ctx (const constexpr_ctx *ctx, constexpr_ctx &new_ctx, 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) diff --git a/gcc/testsuite/g++.dg/cpp2a/no_unique_address16.C b/gcc/testsuite/g++.dg/cpp2a/no_unique_address16.C new file mode 100644 index 000000000000..22c0b699f926 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/no_unique_address16.C @@ -0,0 +1,10 @@ +// 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)}};
