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

--- Comment #9 from CVS 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:7e0b65b239c3a0d68ce94896b236b03de666ffd6

commit r14-1593-g7e0b65b239c3a0d68ce94896b236b03de666ffd6
Author: Jason Merrill <ja...@redhat.com>
Date:   Sun Jun 4 12:09:11 2023 -0400

    c++: enable NRVO from inner block [PR51571]

    Our implementation of the named return value optimization has been limited
    to variables declared in the outermost block of the function, to avoid
    needing to handle the case where the variable needs to be destroyed due to
    going out of scope.  PR92407 pointed out a case we were missing, where the
    variable goes out of scope due to a goto and we were failing to destroy it.

    It occurred to me that this problem is the flip side of PR33799, where we
    need to be sure to destroy the return value if a cleanup throws on return;
    here we want to avoid destroying the return value when exiting the
    variable's scope on return.  We can use the same flag to indicate to both
    cleanups that we're returning.

    This implements the guaranteed copy elision specified by P2025 (which is
not
    yet part of the draft standard).

            PR c++/51571
            PR c++/92407

    gcc/cp/ChangeLog:

            * decl.cc (finish_function): Simplify NRV handling.
            * except.cc (maybe_set_retval_sentinel): Also set if NRV.
            (maybe_splice_retval_cleanup): Don't add the cleanup region
            if we don't need it.
            * semantics.cc (nrv_data): Add simple field.
            (finalize_nrv): Set it.
            (finalize_nrv_r): Check it and retval sentinel.
            * cp-tree.h (finalize_nrv): Adjust declaration.
            * typeck.cc (check_return_expr): Remove named_labels check.

    gcc/testsuite/ChangeLog:

            * g++.dg/opt/nrv23.C: New test.

Reply via email to