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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>:

https://gcc.gnu.org/g:15a7544e09d81fd35edcc32adc08e494e4debcc2

commit r15-6982-g15a7544e09d81fd35edcc32adc08e494e4debcc2
Author: Patrick Palka <ppa...@redhat.com>
Date:   Thu Jan 16 18:28:17 2025 -0500

    c++: RESULT_DECL replacement w/ non-reduced ctx->object [PR105440]

    After surgically replacing RESULT_DECL within a constexpr call result
    (for sake of RVO), we can in some cases simplify the call result
    further.

    In the below testcase the result of get() during evaluation of a's
    initializer is the self-referential CONSTRUCTOR:

      {._M_p=(char *) &<retval>._M_local_buf}

    which after replacing RESULT_DECL with ctx->object (aka *D.2603, where
    the D.2603 temporary points to the current element of _M_elems under
    construction) becomes:

      {._M_p=(char *) &D.2603->_M_local_buf}

    but what we really want is:

      {._M_p=(char *) &a._M_elems[0]._M_local_buf}.

    so that the value of _M_p is independent of the value of the mutable
    D.2603 temporary.

    So to that end, it seems we should constexpr evaluate the result again
    after RESULT_DECL replacement, which is what this patch implements.

            PR c++/105440

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_call_expression): If any RESULT_DECLs get
            replaced in the call result, try further evaluating the result.

    gcc/testsuite/ChangeLog:

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

    Reviewed-by: Jason Merrill <ja...@redhat.com>

Reply via email to