-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter: Brian Bi
Issue description: The coroutine state is intended to be the storage for the parameter copies and promise object, which have automatic storage duration, but the current specification obfuscates this intent and thus fails to specify when the allocation and deallocation functions are called.
Suggested resolution: Edit [dcl.fct.def.coroutine]/10.
Each entry into the replacement body is associated with a region of storage known as the coroutine state, which includes the storage for the promise object and parameter copies (see below). An implementation may need to allocate
additional storage for a coroutinethe coroutine state. This storage is known as the coroutine state and is obtainedby calling a non-array allocation function ([basic.stc.dynamic.allocation])as part ofat the beginning of the replacement body. [...]
Drafting note: The word "includes" is chosen because it is non-exclusive.
Edit [dcl.fct.def.coroutine]/12. As a drive-by fix, remove the duplicative specification of the precondition for std::coroutine_handle::destroy
.
The coroutine state is
destroyedreleased when control flows off the end of the coroutine or thedestroy
member function ([coroutine.handle.resumption]) of a coroutine handle ([coroutine.handle]) that refers to the coroutine is invoked. In the latter case, control in the coroutine is considered to be transferred out of the function ([stmt.dcl]).TheIf allocated, the storage for the coroutine state isreleaseddeallocated by calling a non-array deallocation function ([basic.stc.dynamic.deallocation]).Ifdestroy
is called for a coroutine that is not suspended, the program has undefined behavior.
Edit [dcl.fct.def.coroutine]/14.
When a coroutine is invoked, a copy is created for each coroutine parameter
at the beginning of the replacement body. For a parameter whose original declaration specified the type cv T,
- if T is a reference type, the copy is a reference of type cv T bound to the same object as a parameter;
- otherwise, the copy is a variable of type cv T with automatic storage duration that is direct-initialized from an xvalue of type T referring to the parameter.
[Note 3: ... ]
The initialization and destruction of each parameter copy occurs in the context of the called coroutine. Initializations of parameter copies are sequenced before the call to the coroutine promise constructor and indeterminately sequenced with respect to each other. The lifetime of parameter copies ends immediately after the lifetime of the coroutine promise object ends.The parameter copies are declared in the replacement body immediately before the promise object. The declaration order of the parameter copies with respect to each other is unspecified (even for different invocations of the same coroutine).