Skip to content

[expr.await] The lifetime of parameters and variables that are defined in a coroutine #4867

Open
@xmh0511

Description

@xmh0511

[expr.await] p5

Otherwise, control flow returns to the current coroutine caller or resumer ([dcl.fct.def.coroutine]) without exiting any scopes ([stmt.jump]).

However, whether a variable with automatic storage duration is active or not is totally defined in [stmt.dcl] p3, which means "without exiting any scopes" seems to expound nothing. According to [basic.stc.auto] p1, the storage duration of the parameters and variables defined in a coroutine all have automatic storage duration, hence, their lifetimes are governed by [stmt.dcl] p3. Since what [expr.await] p5 says and [stmt.dcl] p3 says that

when a function returns, Q is after its body.

the lifetime of the parameters of a coroutine has ended when the first suspension occurs (which returns to the caller or resume, that is, Q is after its body). However, it cannot interpret the lifetimes of these variables defined in the body, that is, a suspension may not end their lifetimes.

If we admit the effect of "without exiting any scopes", which in turn, cannot interpret the lifetimes of the parameters of a coroutine, since the parameter scope does not exit out. In conclusion, regardless of [stmt.dcl] p3 or "without exiting any scopes", neither of them can interpret both the lifetime of parameters of the coroutine and the variables in that coroutine.

Activity

changed the title [-][expr.await] The lifetime of parameters and variables of the coroutine[/-] [+][expr.await] The lifetime of parameters and variables that are defined in a coroutine[/+] on Sep 6, 2021
jensmaurer

jensmaurer commented on Sep 6, 2021

@jensmaurer
Member

I'm hearing two concerns here:

  • [stmt.dcl] p3 should tell the complete story, also covering destruction of coroutine parameters and non-destruction of local variables on suspension. Note that [stmt.dcl] p3 says "transfer of control within a function"; arguable suspension does not do that, but transfers control to outside the function.
  • [expr.await] p5 "without exiting any scopes" does not relate to "active" from [stmt.dcl] p3, so we don't know what the former means.
added
decision-requiredA decision of the editorial group (or the Project Editor) is required.
on Sep 6, 2021
xmh0511

xmh0511 commented on Sep 7, 2021

@xmh0511
ContributorAuthor

arguable suspension does not do that, but transfers control to outside the function.

Yes, I was talking about the transfer flow control that occurs after await-suspend evaluation.

added
cwgIssue must be reviewed by CWG.
on Jun 12, 2023
added
not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.
and removed
decision-requiredA decision of the editorial group (or the Project Editor) is required.
on Jun 12, 2023
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

      Development

      No branches or pull requests

        Participants

        @tkoeppe@xmh0511@jensmaurer

        Issue actions

          [expr.await] The lifetime of parameters and variables that are defined in a coroutine · Issue #4867 · cplusplus/draft