]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, coroutines: Allow NVRO in more cases for ramp functions.
authorIain Sandoe <iain@sandoe.co.uk>
Sat, 10 May 2025 16:22:55 +0000 (17:22 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Tue, 29 Jul 2025 15:01:31 +0000 (16:01 +0100)
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.  This is implemented as NVRO but requires that copying
be well-formed even though it will be elided.  Special-case ramp functions
to allow this.

gcc/cp/ChangeLog:

* typeck.cc (check_return_expr): Suppress conversions for NVRO
in coroutine ramp functions.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit d87caa9d3595ca845c9282cef8b0c9a656d8def0)

gcc/cp/typeck.cc

index fb5b04f28e86bf5a8abc5289cb2394417192deed..f6693d99eb86f9c4d63068ac88fb3a6165727e53 100644 (file)
@@ -11584,6 +11584,12 @@ check_return_expr (tree retval, bool *no_warning, bool *dangling)
          && call_from_lambda_thunk_p (retval))
        converted = true;
 
+      /* 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().  */
+      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.  */