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

[basic.stc] Temporary object and its storage duration CWG1634 #4840

Open
xmh0511 opened this issue Aug 26, 2021 · 3 comments
Open

[basic.stc] Temporary object and its storage duration CWG1634 #4840

xmh0511 opened this issue Aug 26, 2021 · 3 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 Aug 26, 2021

[basic.stc.general] p2

Static, thread, and automatic storage durations are associated with objects introduced by declarations ([basic.def]) and implicitly created by the implementation.

The rule explicitly says a temporary object can have a storage duration. However, in the subsequent subclause, the [basic.stc.static], [basic.stc.thread] and [basic.stc.auto] do not state what storage duration the temporary object should have. It only applies to variables.

Since [basic.pre] p6 says

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable's name, if any, denotes the reference or object.

The temporary object is never introduced by a declaration but is created in order to satisfy the requirement of a language construct. Hence, a temporary object is not a variable. This issue is also discussed at https://stackoverflow.com/questions/47945299/what-is-a-temporary-object-with-static-storage-duration

@jensmaurer
Copy link
Member

jensmaurer commented Aug 26, 2021

The intent is that a lifetime-extended temporary bound to a reference inherits the storage duration of the reference, but we don't seem to say that explicitly. One could argue, however, that storage duration is defined as the minimum potential lifetime of an object, and the rules for lifetime-extended temporaries implies that the storage duration must be suitably long to accommodate the lifetime.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 26, 2021

I agree the lifetime has some association with storage duration and vice versa. However, they are not the same things, as discussed in the comment of linked question:

Lifetime and storage duration aren't the same thing. Lifetime is about when the object is a legal C++ object and can have legal, C++ object things done to it. Storage duration is about when the memory backing that object stops existing.

https://stackoverflow.com/questions/47945299/what-is-a-temporary-object-with-static-storage-duration#comment82862476_47945710

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Aug 28, 2021

It seems tracked by the unresolved issue CWG-1634.

@jensmaurer jensmaurer changed the title [basic.stc] Temporary object and its storage duration [basic.stc] Temporary object and its storage duration CWG1634 Aug 29, 2021
@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Aug 29, 2021
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