Title
awaitable-receiver's members are potentially throwing
Status
wp
Section
[exec.as.awaitable]
Submitter
Eric Niebler

Created on 2024-07-30.00:00:00 last changed 3 weeks ago

Messages

Date: 2026-03-31.16:35:58

Proposed resolution:

This wording is relative to N5032.

  1. Modify [exec.as.awaitable] as indicated:

    -4- Let `rcvr` be an rvalue expression of type awaitable-receiver, let `crcvr` be a const lvalue that refers to `rcvr`, let `vs` be a pack of subexpressions, and let `err` be an expression of type `Err`. Let MAKE-NOEXCEPT(expr) for some subexpression `expr` be expression-equivalent to [&] noexcept -> decltype(auto) { return (expr); }(). Then:

    1. (4.1) — If constructible_from<result-type, decltype((vs))...> is satisfied, the expression `set_value(rcvr, vs...)` is equivalent to:

      try {
        rcvr.result-ptr->template emplace<1>(vs...);
      } catch(...) {
        rcvr.result-ptr->template emplace<2>(current_exception());
      }
      MAKE-NOEXCEPT(rcvr.continuation.resume());
      

      Otherwise, `set_value(rcvr, vs...)` is ill-formed.

    2. (4.2) — The expression `set_error(rcvr, err)` is equivalent to:

      try {
        rcvr.result-ptr->template emplace<2>(AS-EXCEPT-PTR(err));
      } catch(...) {
        rcvr.result-ptr->template emplace<2>(current_exception());
      }
      MAKE-NOEXCEPT(rcvr.continuation.resume());
      
    3. (4.3) — The expression `set_stopped(rcvr)` is equivalent to:

      MAKE-NOEXCEPT(static_cast<coroutine_handle<>>(rcvr.continuation.promise().unhandled_stopped()).resume());
      
    4. (4.4) — For any expression `tag` whose type satisfies forwarding-query and for any pack of subexpressions `as`, `get_env(crcvr).query(tag, as...)` is expression-equivalent to:

      tag(get_env(as_const(MAKE-NOEXCEPT(crcvr.continuation.promise()))), as...)
      
Date: 2026-03-31.16:35:58

[ Croydon 2026-03-28; Status changed: Immediate → WP. ]

Date: 2026-03-27.17:12:50

[ Croydon 2026-03-27; Status changed: New → Immediate. ]

Date: 2026-03-15.00:00:00

[ 2026-03-27; Tim adds wording following LWG discussion ]

Date: 2024-08-15.00:00:00

[ 2024-08-21; Reflector poll ]

Set priority to 1 after reflector poll.

`promise()` can probably be Throws: Nothing (along with a bunch of other coroutine_handle members), but `resume()` certainly can throw. Also AS-EXCEPT-PTR can throw for the `error_code` case (that might be worth a separate issue though).

Date: 2024-07-30.00:00:00

The specification of awaitable-receiver in [exec.as.awaitable]/p4 as of N4988 is not taking into consideration the fact that the resume() and promise() member functions on coroutine_handle<P> are not marked noexcept. awaitable-receiver's member functions must all be noexcept, but they are specified as being "equivalent to" statement that call resume() and promise() outside of try/catch blocks.

History
Date User Action Args
2026-03-31 16:35:58adminsetmessages: + msg16192
2026-03-31 16:35:58adminsetstatus: immediate -> wp
2026-03-27 17:12:50adminsetmessages: + msg16141
2026-03-27 17:12:50adminsetstatus: new -> immediate
2026-03-27 16:52:29adminsetmessages: + msg16140
2026-03-27 16:52:29adminsetmessages: + msg16139
2024-08-21 15:02:31adminsetmessages: + msg14328
2024-07-30 00:00:00admincreate