https://gcc.gnu.org/g:cbbe33f2a1959dbf18d724957b3e0d130c8e8797
commit r15-11265-gcbbe33f2a1959dbf18d724957b3e0d130c8e8797 Author: Jason Merrill <[email protected]> Date: Fri Jun 5 11:18:49 2026 -0400 Revert "c++: fix constexpr union with empty member [PR123346]" This reverts commit 38228ed4281a2a3beb0ac920085861cd300c1d6f. Diff: --- gcc/cp/constexpr.cc | 18 ++++-------------- gcc/testsuite/g++.dg/cpp2a/constexpr-union10.C | 8 -------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 2935d24211d0..5adcf0a715b8 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5432,17 +5432,8 @@ init_subob_ctx (const constexpr_ctx *ctx, constexpr_ctx &new_ctx, if (!AGGREGATE_TYPE_P (type) && !VECTOR_TYPE_P (type)) /* A non-aggregate member doesn't get its own CONSTRUCTOR. */ return; - - tree ctxtype = NULL_TREE; - if (ctx->ctor) - ctxtype = TREE_TYPE (ctx->ctor); - else if (ctx->object) - ctxtype = TREE_TYPE (ctx->object); - else - gcc_unreachable (); - if (VECTOR_TYPE_P (type) - && VECTOR_TYPE_P (ctxtype) + && VECTOR_TYPE_P (TREE_TYPE (ctx->ctor)) && index == NULL_TREE) /* A vector inside of a vector CONSTRUCTOR, e.g. when a larger vector is constructed from smaller vectors, doesn't get its own @@ -5461,10 +5452,9 @@ init_subob_ctx (const constexpr_ctx *ctx, constexpr_ctx &new_ctx, new_ctx.object = build_ctor_subob_ref (index, type, ctx->object); } - if (is_empty_class (type) - && TREE_CODE (ctxtype) != UNION_TYPE) - /* Leave ctor null for an empty subobject of a non-union class, they aren't - represented in the result of evaluation. */ + if (is_empty_class (type)) + /* Leave ctor null for an empty subobject, they aren't represented in the + result of evaluation. */ new_ctx.ctor = NULL_TREE; else { diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-union10.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-union10.C deleted file mode 100644 index 36b0fe8fa1b5..000000000000 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-union10.C +++ /dev/null @@ -1,8 +0,0 @@ -// PR c++/123346 -// { dg-do compile { target c++20 } } -struct Unit {}; -union Union { Unit unit; }; -constexpr Union make(Union&& other) { - return Union {.unit = other.unit }; -} -constexpr Union u = make(Union { .unit = Unit{} });
