This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
task
's coroutine frame may be released lateSection: 33.13.6 [exec.task] Status: New Submitter: Dietmar Kühl Opened: 2025-08-31 Last modified: 2025-09-01
Priority: Not Prioritized
View all issues with New status.
Discussion:
The specification of task
doesn't spell out when the
coroutine frame is destroyed (i.e., when handle.destroy()
is called). As a result the lifetime of arguments passed to the
coroutine and/or of local variables in the coroutine body may be
longer than expected.
The intention is that the coroutine frame is destroyed before any
of the completion functions is called. One implication of this
requirement is that the result and error objects can't be stored
in the promise_type
when the completion function is
called although the exposition-only members result
and errors
imply exactly that. Instead the data
needs to be stored in the operation state object or it needs to be
moved to a different place before calling destroy()
.
The proposed resolution is to add a paragraph to the specification
of promise_type
in 33.13.6.5 [task.promise] that spells
out that the coroutine frame is destroyed before any of the completion
functions is called. To actually do that the exposition-only members
result
and errors
can't
remain as members of the promise_type
. While writing
the relevant change it turned out that errors
is a variant
which only ever stores an
exception_ptr
(the other potential errors are immediately
reported via the awaiter return from yield_value
).
Thus, the variant
can be replaced with an
exception_ptr
.
Proposed resolution: