Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xmh0511 opened this issue Sep 6, 2021 · 2 comments
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 6, 2021

[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.

@xmh0511 xmh0511 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 Sep 6, 2021
@jensmaurer
Copy link
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.

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Sep 6, 2021
@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 7, 2021

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.

@tkoeppe tkoeppe added the cwg Issue must be reviewed by CWG. label Jun 12, 2023
@jensmaurer jensmaurer added not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. and removed decision-required A decision of the editorial group (or the Project Editor) is required. labels Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

No branches or pull requests

3 participants