https://gcc.gnu.org/g:f42b8129338fe36c9cf2031c0ac66ffadb881a10
commit r14-12640-gf42b8129338fe36c9cf2031c0ac66ffadb881a10 Author: Jason Merrill <[email protected]> Date: Mon Jun 8 02:58:33 2026 -0400 Revert "c++: fix constexpr union with empty member [PR123346]" This reverts commit 660fa7fd354b71f864f67e5e1966a6e62f8a2c3b. 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 55086b930e73..6ec87be560b6 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5285,17 +5285,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 @@ -5314,10 +5305,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{} });
