[PATCH] c++, libstdc++, v2: Implement C++26 P3074R7, P3726R0 and CWG3189 - trivial unions [PR119059]

Jakub Jelinek jakub@redhat.com
Thu May 21 07:59:50 GMT 2026


On Thu, May 21, 2026 at 08:37:46AM +0200, Tomasz Kaminski wrote:
> I would still like to see cases where the default constructor is not the
> one creating the union.
> Destructor deleted.
> struct R { R () = default; R(int); union { int a; G b; }; };
> static_assert (std::is_default_constructible <R>::value, "");
> static_assert (std::is_trivially_default_constructible <R>::value, "");
> static_assert (!std::is_destructible <R>::value, "");
> static_assert (!std::is_trivially_destructible <R>::value, "");
> 
> struct Q { Q(int); union { int a; G b; }; };
> static_assert (!std::is_default_constructible <Q>::value, "");
> static_assert (!std::is_trivially_default_constructible <Q>::value, "");
> static_assert (!std::is_destructible <Q>::value, "");
> static_assert (!std::is_trivially_destructible <Q>::value, "");

Added those and a few others.

> Have you considered using templates for this tests, to have something like
> this?
> I will find that easier to follow, but it does not seem to be used in the
> core tests,
> so feel free to ignore that suggestions. (Unions could also be tested this
> way).

That is a usual libstdc++ test style, sure (and I guess it wouldn't hurt
if some libstdc++ tests are added for this too), but unusual in g++.dg and for
a reason, when one needs to debug what exactly is going in some particular
case the harder it is to actually extract the bare minimum the more time
one needs to spend on it.  So, in g++.dg whenever possible we want no
headers and code reduced to minimum extra layers.
Also, note that for this particular cases there are 2 separate tests, one
with the 2 <type_traits> and another one with reflection; the reason is
that the former allows testing how it behaves in C++11-C++23 as well in
the same test, the latter has the advantage that it can inspect the
individual ctor/dtor properties (defaulted, deleted, trivial) rather than
some combination of those only.

	Jakub



More information about the Libstdc++ mailing list