diff options
author | Jason Merrill <jason@redhat.com> | 2023-06-04 12:09:11 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-06-06 21:31:31 -0400 |
commit | 7e0b65b239c3a0d68ce94896b236b03de666ffd6 (patch) | |
tree | f64aca7b8eb03218b0de96a1925666483966791b /gcc/expr.cc | |
parent | b192e2007e1c98b548f4aa878523b485968d24a4 (diff) | |
download | gcc-7e0b65b239c3a0d68ce94896b236b03de666ffd6.zip gcc-7e0b65b239c3a0d68ce94896b236b03de666ffd6.tar.gz gcc-7e0b65b239c3a0d68ce94896b236b03de666ffd6.tar.bz2 |
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.
Diffstat (limited to 'gcc/expr.cc')
0 files changed, 0 insertions, 0 deletions