================ @@ -8281,8 +8288,62 @@ Example: co_await t; } -The behavior is undefined if the caller coroutine is destroyed earlier than the -callee coroutine. +Such elision replaces the heap allocated activation frame of the callee coroutine +with a local variable within the enclosing braces in the caller's stack frame. +The local variable, like other variables in coroutines, may be collected into the +coroutine frame, which may be allocated on the heap. The behavior is undefined +if the caller coroutine is destroyed earlier than the callee coroutine. + +}]; +} + +def CoroMustAwaitDoc : Documentation { + let Category = DocCatDecl; + let Content = [{ + +The ``[[clang::coro_must_await]]`` is a function parameter attribute. It works +in conjunction with ``[[clang::coro_await_elidable]]`` to propagate a safe elide +context to a parameter or parameter pack if the function is called under a safe +elide context. + +This is sometimes necessary on utility functions whose role is to compose or +modify the behavior of a callee coroutine. + +Example: + +.. code-block:: c++ + + template <typename T> + class [[clang::coro_await_elidable]] Task { ... }; + + template <typename... T> + class [[clang::coro_await_elidable]] WhenAll { ... }; + + // `when_all` is a utility function that compose coroutines. It does not need + // to be a coroutine to propagate. + template <typename... T> + WhenAll<T...> when_all([[clang::coro_must_await]] Task<T> tasks...); + + Task<int> foo(); + Task<int> bar(); + Task<void> example1() { + // `when_all``, `foo``, and `bar` are all elide safe because `when_all` is + // under a safe elide context and propagated such contexts to foo and bar. ---------------- vogelsgesang wrote:
```suggestion // under a safe elide context and, thanks to the [[coro_must_await]] attribute, // this context is propagated to foo and bar. ``` https://github.com/llvm/llvm-project/pull/108474 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits