https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407
--- Comment #7 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:b192e2007e1c98b548f4aa878523b485968d24a4 commit r14-1592-gb192e2007e1c98b548f4aa878523b485968d24a4 Author: Jason Merrill <ja...@redhat.com> Date: Sun Jun 4 12:00:55 2023 -0400 c++: NRV and goto [PR92407] Here our named return value optimization was breaking the required destructor when the goto takes 'a' out of scope. The simplest fix is to disable the optimization in the presence of user labels. We could do better by disabling the optimization only if there is a backward goto across the variable declaration, but we don't currently track that. PR c++/92407 gcc/cp/ChangeLog: * typeck.cc (check_return_expr): Prevent NRV in the presence of named labels. gcc/testsuite/ChangeLog: * g++.dg/opt/nrv22.C: New test.