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

--- Comment #18 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <[email protected]>:

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

commit r17-110-ge9d43010d8ec98eed9a81ec4535ce446cc0e9c94
Author: Jason Merrill <[email protected]>
Date:   Mon Apr 20 15:46:05 2026 -0400

    c++: constexpr union with no active member [PR124910]

    Patrick pointed out that while r16-8767 made a union constant after
    destroying its active member, we still weren't treating a union that never
    had an active member as constant; the difference is the
    CONSTRUCTOR_NO_CLEARING flag, and what that means to
    reduced_constant_expression_p.

    It seems to me that since P2686 [expr.const] says whether a prvalue
    expression is a constant expression depends on the constituent values, and
    [intro.object] says that only the active member is a constituent value of a
    union, so a union with no active member has no constituent values and so is
    vacuously constant, like an object of empty type.  P2686 as a whole is not
a
    DR, but the draft was previously unclear, and CWG2658 also clarified that
    copying a union is equivalent to copying the active member *if any*.

    I was somewhat surprised that none of the existing tests needed to be
    changed.

            PR c++/124910
            DR 2658

    gcc/cp/ChangeLog:

            * constexpr.cc (reduced_constant_expression_p): Allow a union
            with no active member.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/constexpr-union12.C: New test.

Reply via email to