On 5/29/25 6:56 AM, Iain Sandoe wrote:
Tested on x86_64-darwin, confirming that the original reported code
fails without the change here.  Unfortunately, if we add a move
constructor to the reduced case, it no longer fails on unpatched
trunk - so not proposing to add that as a testcase (since it tests
something unrelated to coroutines).

Actually, I think I was wrong and the reduced testcase is fine after all -- the problem was indeed of trying to check the conversion for a class without a move constructor, when we want to avoid that check with NRVO in a ramp.

In the original testcase TaskBase has a move constructor, but LazyTask still doesn't. Adding a move constructor to TaskBase and a destructor to LazyTask in the reduced testcase would more precisely preserve the situation, but I think the reduced testcase without changes is good enough.

So please do add the testcase.  OK with that change.

OK for trunk?
thanks
Iain

--- 8< ---

The existing implementation, incorrectly, tried to use DECL_RAMP_FN
in check_return_expr to determine if we are handling a ramp func.
However, that query is only set for the resume/destroy functions.

Replace the use of DECL_RAMP_FN with a new query.

        PR c++/120453

gcc/cp/ChangeLog:

        * cp-tree.h (DECL_RAMP_P): New.
        * typeck.cc (check_return_expr): Use DECL_RAMP_P instead
        of DECL_RAMP_FN.

Signed-off-by: Iain Sandoe <i...@sandoe.co.uk>
---
  gcc/cp/cp-tree.h | 4 ++++
  gcc/cp/typeck.cc | 2 +-
  2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 19c0b452d86..d9fc80b92e5 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5522,6 +5522,10 @@ decl_template_parm_check (const_tree t, const char *f, 
int l, const char *fn)
  #define DECL_RAMP_FN(NODE) \
    (coro_get_ramp_function (NODE))
+/* For a FUNCTION_DECL this is true if it is a coroutine ramp. */
+#define DECL_RAMP_P(NODE) \
+  DECL_COROUTINE_P (NODE) && !DECL_RAMP_FN (NODE)
+
  /* True for an OMP_ATOMIC that has dependent parameters.  These are stored
     as an expr in operand 1, and integer_zero_node or clauses in operand 0.  */
  #define OMP_ATOMIC_DEPENDENT_P(NODE) \
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index af2cbaff8fd..ac1eb397f01 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -11466,7 +11466,7 @@ check_return_expr (tree retval, bool *no_warning, bool 
*dangling)
        /* 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)
+      if (DECL_RAMP_P (current_function_decl) && named_return_value_okay_p)
        converted = true;
/* First convert the value to the function's return type, then

Reply via email to