Title
Precondition of coroutine_handle::promise may be insufficient
Status
resolved
Section
[coroutine.handle.promise]
Submitter
Jiang An

Created on 2020-07-25.00:00:00 last changed 49 months ago

Messages

Date: 2020-11-09.22:09:52

Proposed resolution:

This issue is resolved by the resolution of issue 3460.

Date: 2020-11-09.00:00:00

[ 2020-11-09 Resolved by acceptance of 3460. Status changed: Tentatively Resolved → Resolved. ]

Date: 2020-08-15.00:00:00

[ 2020-08-21; Reflector prioritization ]

Set priority to 2 after reflector discussions.

Previous resolution [SUPERSEDED]:

This wording is relative to N4861.

  1. Modify [coroutine.handle.promise] as indicated:

    Promise& promise() const;
    

    -1- Preconditions: *this refers to a coroutine whose promise type is Promise.

    -2- Returns: A reference to the promise of the coroutine.

  2. Modify [coroutine.handle.noop], class coroutine_handle<noop_coroutine_promise> synopsis, as indicated:

    […]
    // [coroutine.handle.noop.promise], promise access
    noop_coroutine_promise& promise() const noexcept;
    […]
    
  3. Modify [coroutine.handle.noop.promise] as indicated:

    noop_coroutine_promise& promise() const noexcept;
    

    -?- Preconditions: *this refers to a coroutine whose promise type is noop_coroutine_promise.

    -1- Returns: A reference to the promise object associated with this coroutine handle.

Date: 2020-08-21.13:37:22

The issue is related to LWG 3460.

Because the coroutine_handle<> base subobject of a coroutine_handle<P1> can be assigned from the one of a coroutine_handle<P2>, a coroutine_handle<P1> may refer to a coroutine whose promise type is P2. If a coroutine_handle<P> refers to a coroutine with difference, a call to promise() should result in undefined behavior IMO.

I think that [coroutine.handle.promise]/1 should be changed to: "Preconditions: *this refers to a coroutine whose promise type is Promise.", and the same precondition should be added to [coroutine.handle.noop.promise], and hence noexcept should be removed from coroutine_handle<noop_coroutine_promise>::promise.

History
Date User Action Args
2020-11-09 22:09:52adminsetmessages: + msg11594
2020-08-21 20:18:09adminsetstatus: new -> resolved
2020-08-21 13:37:22adminsetmessages: + msg11439
2020-07-26 14:33:55adminsetmessages: + msg11417
2020-07-25 00:00:00admincreate