Description
Task task(){
std::cout<<"in task\n";
int r = co_await Line();
std::cout<<"resumed\n";
co_return r;
}
auto r = task();
auto c = (r.coro_.resume(),0); // #1
auto f = [](){
std::cout<<"invoked\n";
return 0;
}();
int main(){}
#1
is a declaration where its initializer expression will invoke the resumption member function of the coroutine. We just state that:
A suspended coroutine can be resumed to continue execution by invoking a resumption member function ([coroutine.handle.resumption]) of a coroutine handle ([coroutine.handle]) that refers to the coroutine. The function that invoked a resumption member function is called the resumer.
and we have specified that
A coroutine returns to its caller or resumer ([dcl.fct.def.coroutine]) by the co_return statement or when suspended ([expr.await]).
Obviously, in this case, the call of the resumption member function at #1
causes the coroutine to be resumed, and the co_return statement can cause the coroutine to return to its resumer, which means the lambda will be subsequently invoked. The complete example is here. The implementation admits that the context at #1
is also a so-called resumer.
Activity
[-]The resumer of a coroutine may not be a function[/-][+][dcl.fct.def.coroutine] The resumer of a coroutine may not be a function[/+][-][dcl.fct.def.coroutine] The resumer of a coroutine may not be a function[/-][+][dcl.fct.def.coroutine] The resumer of a coroutine may not be a function CWG2613[/+]jensmaurer commentedon Aug 24, 2022
CWG2613
frederick-vs-ja commentedon Aug 1, 2023
Should have been fixed by #5984 (d9dc415).