[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

Yuxuan Chen via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 26 13:57:10 PDT 2024


================
@@ -418,39 +448,60 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, VarDecl *CoroPromise,
     return Calls;
   }
   Expr *CoroHandle = CoroHandleRes.get();
-  CallExpr *AwaitSuspend = cast_or_null<CallExpr>(
-      BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle));
+  auto *AwaitSuspend = [&]() -> CallExpr * {
+    auto *SubExpr = BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle);
+    if (!SubExpr)
+      return nullptr;
+    if (auto *E = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) {
+      // This happens when await_suspend return type is not trivially
+      // destructible. This doesn't happen for the permitted return types of
+      // such function. Diagnose it later.
+      return cast_or_null<CallExpr>(E->getSubExpr());
+    } else {
+      return cast_or_null<CallExpr>(SubExpr);
+    }
----------------
yuxuanchen1997 wrote:

Currently the diagnostic will read:

```
error: return type of 'await_suspend' is required to be 'void', 'bool', or 'std::coroutine_handle' (have 'Status')
```

With what you suggested, I cannot print the "have 'Status'" part any more. 

https://github.com/llvm/llvm-project/pull/85684


More information about the cfe-commits mailing list