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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <ja...@gcc.gnu.org>:

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

commit r16-2432-gfdbc5ff61b471076cc9c758fb6c30d62f7ef1c56
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Jul 16 11:52:45 2025 -0400

    c++: constexpr union placement new [PR121068]

    The note and example in [class.union] p6 think that placement new can be
    used to change the active member of a union, but we didn't support that for
    array members in constant-evaluation even after implementing P1330 and
    P2747.

    First I tried to address this by introducing a CLOBBER_BEGIN_OBJECT for the
    entire array, but that broke the resolution of LWG3436, which invokes 'new
    T[1]' for an array T, and trying to clobber a multidimensional array when
    the actual object is single-dimensional breaks.  So I've raised that issue
    with the committee.  Until that is resolved, this patch takes a simpler
    approach: allow initialization of an element of an array to make the array
    the active member of a union.

            PR c++/121068

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_store_expression): Allow ARRAY_REFs
            when activating an array member of a union.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/constexpr-union6.C: Expect x5 to work.
            * g++.dg/cpp26/constexpr-new4.C: New test.

Reply via email to