https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119059

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:ca6cd7cb48512d60c28024174b319df4580498ce

commit r17-671-gca6cd7cb48512d60c28024174b319df4580498ce
Author: Jakub Jelinek <[email protected]>
Date:   Fri May 22 10:15:45 2026 +0200

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

    The following patch attempts to implement the C++26
    P3074R7 - trivial unions (was std::uninitialized<T>)
    paperand proposed resolution of
    CWG3189 - Implicitly deleted destructors for union-like classes
    with the exception of the
      #define __cpp_lib_constexpr_inplace_vector 2025XXL // also in
<inplace_vector>
    addition and possibly needed <inplace_vector> changes (will defer that to
    Jonathan / Tomasz) and except for the changes in [class.default.ctor]/4
which
    were reverted by P3726R2 later on .

    There is one change which doesn't affect just C++26 but also older versions
    of the standard, https://eel.is/c++draft/class.default.ctor#2.2 or its
older
    counterparts, e.g. C++11 had in [class.ctor]/5
    "any non-variant non-static data member of const-qualified type (or array
thereof)
    with no brace-or-equal-initializer does not have a user-provided default
    constructor"
    but we've been ignoring the "non-variant" part thereof and diagnosing it
    for variant members too.  Note, this is related to the other unimplemented
    rule I've posted a patch earlier for that was dismissed (reject
    all variant members const before C++26), so some cases which we've rejected
    for a wrong reason will now be accepted when they are still invalid before
    C++26.

    2026-05-22  Jakub Jelinek  <[email protected]>

            PR c++/119059
    gcc/c-family/
            * c-cppbuiltin.cc (c_cpp_builtins): For C++26 predefine
            __cpp_trivial_union to 202502L.
    gcc/cp/
            * method.cc: Implement C++26 P3074R7 - trivial unions (was
            std::uninitialized<T>) (except the sentence removed again in
P3726R2)
            and proposed resolution of CWG3189 - Implicitly deleted destructors
            for union-like classes.
            (walk_field_subobs): Don't do default_init_uninitialized_part
checks
            for variant members.  Don't check subobject ctor/dtor for variant
            members for ctor/inheriting ctor or when subobject doesn't have
member
            initializer for dtor and it is either the dtor_from_ctor case or
            the current class doesn't have user provided ctors.
            * class.cc (check_field_decl): Don't or in
            TYPE_HAS_NONTRIVIAL_DESTRUCTOR or TYPE_HAS_DEFAULT_CONSTRUCTOR of
            variant subobjects for C++26.
    gcc/testsuite/
            * g++.dg/DRs/dr2581-1.C: Expect warning for __cpp_trivial_union.
            * g++.dg/DRs/dr2581-2.C: Expect error for __cpp_trivial_union.
            * g++.dg/cpp26/feat-cxx26.C: Add __cpp_trivial_union checking.
            * g++.dg/cpp26/trivial-union1.C: New test.
            * g++.dg/cpp26/trivial-union2.C: New test.
            * g++.dg/reflect/trivial-union1.C: New test.
            * g++.dg/reflect/type_trait6.C: Adjust expected result of
            one is_destructible_type and two is_nothrow_destructible_type
calls.
            * g++.dg/reflect/is_constructible_type1.C: Adjust expected result
            of one is_constructible_type call.
            * g++.dg/init/pr43719.C: Don't expect one error.
            * g++.dg/init/pr25811.C: Don't expect 3 diagnostic messages,
            instead expect a different one for C++98 only.
            * g++.dg/other/anon-union2.C: Only expect one diagnostic for
            C++23 and older.
            * g++.dg/cpp0x/union1.C: Only expect 6 diagnostic messages for
            C++23 and older.
            * g++.dg/cpp0x/union4.C: Only expect 3 diagnostic messages for
            C++23 and older.
            * g++.dg/cpp0x/defaulted2.C: Only expect 2 diagnostic messages for
            C++23 and older.

    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to