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

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

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

commit r16-7199-ge4c57e146a224d0aaa71ace78f96fca1156add24
Author: Patrick Palka <[email protected]>
Date:   Fri Jan 30 15:25:43 2026 -0500

    c++: non-empty constexpr constructor bodies in C++11 [PR123845]

    This patch makes us support C++14 non-empty constexpr constructor bodies
    in C++11, as an extension.  This will make it trivial to safely fix the
    C++11 library regression PR114865 that requires us to do
    __builtin_clear_padding after initializing _M_i in std::atomic's
    single-parameter constructor, and that's not really possible with the
    C++11 constexpr restrictions.

    Since we lower member initializers to constructor body statements
    internally, and so constructor bodies are already effectively non-empty
    internally even in C++11, supporting non-empty bodies in user code is
    mostly a matter of relaxing the parse-time error.

    But constexpr-ex3.C revealed that by accepting the non-empty body of A's
    constructor, build_data_member_initialization goes on to mistake the
    'i = _i' assignment as a member initializer, and we incorrectly accept
    the constructor in C++11 mode (even though omitting mem-inits is only
    valid since C++20).  Turns out this is caused by that function
    recognizing MODIFY_EXPR only in C++11 mode, logic that was last changed
    by r5-5013 (presumably to limit impact of the patch at the time) but I
    reckon could just be removed outright.  This should be safe because the
    result of build_data_member_initialization is only used by
    cx_check_missing_mem_inits for validation; evaluation is in terms of
    the entire lowered constructor body.

            PR c++/123845
            PR libstdc++/114865

    gcc/cp/ChangeLog:

            * constexpr.cc (build_data_member_initialization): Remove
            C++11-specific recognition of MODIFY_EXPR.
            (check_constexpr_ctor_body): Relax error diagnostic to a
            pedwarn and don't clear DECL_DECLARED_CONSTEXPR_P upon
            error.  Return true if complaining.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-ex3.C: Adjust C++11 non-empty
            constexpr constructor dg-error to a dg-warning.  Expect
            a follow-up missing member initializer diagnostic in C++11 mode.
            * g++.dg/cpp2a/constexpr-try1.C: Expect a follow-up
            compound-statement in constexpr function diagnostic in C++11
            mode.
            * g++.dg/cpp2a/constexpr-try2.C: Likewise.  Adjust C++11
            non-empty constexpr constructor dg-error to a dg-warning.
            * g++.dg/cpp2a/constexpr-try3.C:  Adjust C++11 non-empty
            constexpr constructor dg-error to a dg-warning.
            * g++.dg/cpp0x/constexpr-ctor23.C: New test.

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

Reply via email to