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

CWG2976 [stmt.dcl] p2 Destruction of variables with automatic storage duration on coroutine exit #656

Open
dedlocc opened this issue Dec 20, 2024 · 3 comments

Comments

@dedlocc
Copy link

dedlocc commented Dec 20, 2024

Full name of submitter: Artem Koton

Reference (section label): [stmt.dcl] p2

Issue description:

P1787 changed the wording of [dcl.fct.def.coroutine/11] regarding the destruction of variables with automatic storage duration from:

In the latter case objects with automatic storage duration that are in scope at the suspend point are destroyed in the reverse order of the construction.

to:

In the latter case, control in the coroutine is considered to be transferred out of the function ([stmt.dcl/2]).

According to [stmt.dcl/2]:

Upon each transfer of control (including sequential execution of statements) within a function from point P to point Q, all block variables with automatic storage duration that are active at P and not at Q are destroyed in the reverse order of their construction.

This only applies to transferring control "within a function", which does not seem to cover the case for coroutines. If so, there currently appears to be no wording specifying how local variables are destroyed when a coroutine is exited.

Suggested resolution:

Clarify the wording of [stmt.dcl/2] to cover transfers of control out of a function.

@jensmaurer
Copy link
Member

"when a function returns, Q is after its body."

Do you feel some phrasing is missing to have this cover coroutines?

@villevoutilainen
Copy link
Member

villevoutilainen commented Dec 20, 2024

There's also the thing that "within a function" doesn't mean that both the source and target of a control transfer are within a function, but the control transfer operation is within a function.

Jens, we could clarify this with
Upon each transfer of control (including sequential execution of statements) within <ins>or out of</ins> a function.

@jensmaurer jensmaurer changed the title [stmt.dcl] p2 Destruction of variables with automatic storage duration on coroutine exit CWG2976 [stmt.dcl] p2 Destruction of variables with automatic storage duration on coroutine exit Dec 27, 2024
@jensmaurer
Copy link
Member

CWG2976

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants