]> gcc.gnu.org Git - gcc.git/commit
c++: allow NRV and non-NRV returns [PR58487]
authorJason Merrill <jason@redhat.com>
Wed, 7 Jun 2023 09:15:02 +0000 (05:15 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 7 Jun 2023 22:06:26 +0000 (18:06 -0400)
commit28db36e2cfca1b7106adc8d371600fa3a325c4e2
tree794314078aa0d221044c00a42a72367f25212057
parent941209f9da23b4e0f338ed970012fcfa7b20e528
c++: allow NRV and non-NRV returns [PR58487]

Now that we support NRV from an inner block, we can also support non-NRV
returns from other blocks, since once the NRV is out of scope a later return
expression can't possibly alias it.

This fixes 58487 and half-fixes 53637: now one of the returns is elided, but
not the other.

Fixing the remaining xfails in these testcases will require a very different
approach, probably involving a full tree/block walk from finalize_nrv, and
check_return_expr only adding to a list of potential return variables.

PR c++/58487
PR c++/53637

gcc/cp/ChangeLog:

* cp-tree.h (INIT_EXPR_NRV_P): New.
* semantics.cc (finalize_nrv_r): Check it.
* name-lookup.h (decl_in_scope_p): Declare.
* name-lookup.cc (decl_in_scope_p): New.
* typeck.cc (check_return_expr): Allow non-NRV
returns if the NRV is no longer in scope.

gcc/testsuite/ChangeLog:

* g++.dg/opt/nrv26.C: New test.
* g++.dg/opt/nrv26a.C: New test.
* g++.dg/opt/nrv27.C: New test.
gcc/cp/cp-tree.h
gcc/cp/name-lookup.cc
gcc/cp/name-lookup.h
gcc/cp/semantics.cc
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/opt/nrv26.C [new file with mode: 0644]
gcc/testsuite/g++.dg/opt/nrv26a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/opt/nrv27.C [new file with mode: 0644]
This page took 0.068167 seconds and 6 git commands to generate.