Skip to content

[dcl.fct.def.coroutine] The resumer of a coroutine may not be a function CWG2613 #5295

Open
@xmh0511

Description

@xmh0511
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

added
cwgIssue must be reviewed by CWG.
not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.
on Aug 24, 2022
changed the title [-]The resumer of a coroutine may not be a function[/-] [+][dcl.fct.def.coroutine] The resumer of a coroutine may not be a function[/+] on Aug 24, 2022
changed the title [-][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[/+] on Aug 24, 2022
jensmaurer

jensmaurer commented on Aug 24, 2022

@jensmaurer
Member
frederick-vs-ja

frederick-vs-ja commented on Aug 1, 2023

@frederick-vs-ja
Contributor

Should have been fixed by #5984 (d9dc415).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cwgIssue must be reviewed by CWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @xmh0511@frederick-vs-ja@jensmaurer

      Issue actions

        [dcl.fct.def.coroutine] The resumer of a coroutine may not be a function CWG2613 · Issue #5295 · cplusplus/draft