]> 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>
Tue, 29 Jul 2025 15:10:43 +0000 (16:10 +0100)
commitf67c851f03cf14c82a43045ea567ab5fb06377ac
treed533305c2f574f3ca5e3cee4ce0670ed800ce6bc
parent823d5948aa2d8937befcb35f7b1bb9e33346efd9
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>
(cherry picked from commit a2775feb7c7de9f21f79052e2b6a752a3eb08f07)
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/torture/pr121219.C [new file with mode: 0644]