]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++, coroutines: Handle allocation fail returns [PR121219].
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 23 Jul 2025 15:22:32 +0000 (16:22 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 25 Jul 2025 11:31:01 +0000 (12:31 +0100)
commita2775feb7c7de9f21f79052e2b6a752a3eb08f07
treeabf22e50981e733db8a24ec8cba4518228fce3cc
parentf888d5fbea1820ac75d84dfef0a974e578670394
c++, coroutines: Handle allocation fail returns [PR121219].

The current implementation was returning the result of the g_r_o_o_a_f
call independently of the return expressions for 'normal' cases.

This prevents the NVRO that we need to guarantee copy elision for the
ramp return values - when these are initialised from a temporary of the
same type.

The solution here reorders the code so that the regular return expression
appears before the allocation-failed case.  Ensure that the g_r_o and
associated code appears in a distinct scope.  These steps are to meet the
constaints of NRV.

PR c++/121219

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::build_ramp_function): Reorder the return
expressions for the 'normal' and 'allocation failed' cases so that
NRV constraints are met.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/torture/pr121219.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/torture/pr121219.C [new file with mode: 0644]