[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 13 05:22:00 PST 2023


================
@@ -15811,6 +15813,32 @@ static void diagnoseImplicitlyRetainedSelf(Sema &S) {
           << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+// Return whether FD is `promise_type::get_return_object`.
+bool isGetReturnObject(FunctionDecl *FD) {
+  if (!FD->getDeclName().isIdentifier() ||
+      !FD->getName().equals("get_return_object") || !FD->param_empty())
+    return false;
+  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
+  if (!MD || !MD->isCXXInstanceMember())
+    return false;
+  RecordDecl *PromiseType = MD->getParent();
+  return PromiseType && PromiseType->getDeclName().isIdentifier() &&
----------------
ilya-biryukov wrote:

Why do we restrict the name of the class itself to be `promise_type`?
It's valid to have code like:
```cpp
struct any_name_i_want {
  // that's the promise type.
  // includes `get_return_object` implementation too.
};

struct coro_task {
  using promise_type = any_name_i_want;
};
```

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


More information about the cfe-commits mailing list