[clang] [C++20][Coroutines] Lambda-coroutine with operator new in promise_type (PR #84193)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 21:47:34 PST 2024


================
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -I%S/Inputs -std=c++20 %s
+
+// expected-no-diagnostics
+
+#include "std-coroutine.h"
+
+using size_t = decltype(sizeof(0));
+
+struct Generator {
+  struct promise_type {
+    int _val{};
+
+    Generator get_return_object() noexcept
+    {
+      return {};
+    }
+
+    std::suspend_never initial_suspend() noexcept
+    {
+      return {};
+    }
+
+    std::suspend_always final_suspend() noexcept
+    {
+      return {};
+    }
+
+    void return_void() noexcept {}
+    void unhandled_exception() noexcept {}
+
+    template<typename This, typename... TheRest>
+    static void*
+    operator new(size_t size,
+                 This&,
+                 TheRest&&...) noexcept
+    {
+        return nullptr;
+    }
+
+    static void operator delete(void*, size_t)
+    {
+    }
+  };
+};
+
+int main()
+{
+  auto lamb = []() -> Generator {
----------------
shafik wrote:

What should happen if the lambda has a capture? Is it allowed?

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


More information about the cfe-commits mailing list