On 5/13/25 10:30 AM, Iain Sandoe wrote:
The constraints of the c++ coroutines specification require the ramp to construct a return object early in the function. This will be returned at some later time. To meet the requirements of copy-elision, we need to ensure NVRO for these objects, even when they are non-copyable or non-movable. Special-case ramp functions to allow this.
Note that the compiler was already choosing to do NRVO in this case, it just required the copy to be well-formed even though it's getting elided.
gcc/cp/ChangeLog: * typeck.cc (check_return_expr): Suppress conversions for NVRO in coroutine ramp functions. Signed-off-by: Iain Sandoe <i...@sandoe.co.uk> --- gcc/cp/typeck.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 1b9fdf5b21d..d8bc3409984 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -11463,6 +11463,9 @@ check_return_expr (tree retval, bool *no_warning, bool *dangling) && call_from_lambda_thunk_p (retval)) converted = true;
Let's add /* Don't check copy-initialization for NRV in a coroutine ramp; we implement this case as NRV, but it's specified as directly initializing the return value from get_return_object(). */ OK with that tweak.
+ if (DECL_RAMP_FN (current_function_decl) && named_return_value_okay_p) + converted = true; + /* First convert the value to the function's return type, then to the type of return value's location to handle the case that functype is smaller than the valtype. */