]> gcc.gnu.org Git - gcc.git/commit
c++: NRV and goto [PR92407]
authorJason Merrill <jason@redhat.com>
Sun, 4 Jun 2023 16:00:55 +0000 (12:00 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 31 Aug 2023 22:35:53 +0000 (18:35 -0400)
commita645347c19b07cc7abd7bf276c6769fc41afc932
treebe03d99730a66f0c78558ff15619278b5679c662
parentb6786076d9588640db6bc01c467f9760e4c3059c
c++: NRV and goto [PR92407]

Here our named return value optimization was breaking the required
destructor when the goto takes 'a' out of scope.  A simple fix for the
release branches is to disable the optimization in the presence of backward
goto.

We could do better by disabling the optimization only if there is a backward
goto across the variable declaration, but we don't track that, and in GCC 14
we instead make the goto work with NRV.

PR c++/92407

gcc/cp/ChangeLog:

* cp-tree.h (struct language_function): Add backward_goto.
* decl.cc (check_goto): Set it.
* typeck.cc (check_return_expr): Prevent NRV if set.

gcc/testsuite/ChangeLog:

* g++.dg/opt/nrv22.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/opt/nrv22.C [new file with mode: 0644]
This page took 0.06464 seconds and 6 git commands to generate.