Created on 2025-02-14.00:00:00 last changed 1 month ago
Additional notes (November, 2025)
Paper P3726R0 (Adjustments to Union Lifetime Rules) has been approved by EWG and addresses this issue.
Additional notes (September, 2025)
See also P3726R0 (Adjustments to Union Lifetime Rules).
Forwarding to EWG to clarify the intent with paper issue #2418.
Consider:
union U { int a, b; };
template<U u> class X {};
constexpr U make() { U u; return u; }
void f(X<make()>) {}
Before P3074R7, the template argument of X was a union object with no active member. Now, the default construction of U starts the lifetime of U::a because it has implicit-lifetime type (11.4.5.2 [class.default.ctor] paragraph 4).
This changes the mangling of f, because a union with no active member is different from a union with the first member active. More importantly, it is now ill-formed, because U::a is in-lifetime, but uninitialized (7.7 [expr.const] bullet 22.2).
Also consider the following implementation divergence
struct E { };
union U { E e; };
template<U u> class X {};
constexpr U make() { U u; return u; }
constexpr U make2() { U u{}; return u; }
void f(X<make()>) {}
void f(X<make2()>) {} // OK with clang; redefinition error with gcc
If any of those behavior changes are intended, an Annex C entry is needed.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-11-06 13:53:32 | admin | set | messages: + msg8223 |
| 2025-11-06 13:53:32 | admin | set | status: open -> review |
| 2025-09-11 14:31:28 | admin | set | messages: + msg8086 |
| 2025-02-14 00:00:00 | admin | create | |