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

Andreas Fertig via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 22:56:19 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 {
----------------
andreasfertig wrote:

Sure. See my answer above, maybe that helps to understand that we aren't talking about a captured `this`, this time.

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


More information about the cfe-commits mailing list