[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 3 06:22:19 PST 2024


================
@@ -115,3 +115,18 @@ CoNoCRT<int> bar(int a) {
   co_return 1;
 }
 } // namespace not_a_crt
+
+// =============================================================================
+// Not lifetime bound coroutine wrappers: [[clang::coro_not_lifetimebound]].
+// =============================================================================
+namespace not_lifetimebound {
+Co<int> foo(int x) {  co_return x; }
+
+[[clang::coro_wrapper, clang::coro_not_lifetimebound]] 
+Co<int> foo_wrapper(const int& x) { return foo(x); }
+
+[[clang::coro_wrapper]] Co<int> caller() {
+  // The call to foo_wrapper is wrapper is safe.
+  return foo_wrapper(1);
+}
+} // namespace not_lifetimebound
----------------
ilya-biryukov wrote:

NIT: add newline

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


More information about the cfe-commits mailing list