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

Specifying the storage duration of temporary objects (automatic, thread, static, or dynamic?) #4900

Closed
geryogam opened this issue Sep 13, 2021 · 1 comment

Comments

@geryogam
Copy link
Contributor

The standard is vague on the storage duration of temporary objects, as Nicol Bolas explained on Stack Overflow:

[basic.stc]/1 tells us:

The storage duration is the property of an object that defines the minimum potential lifetime of the storage containing the object.

So every object has a storage duration. Further, paragraph 2 says:

Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.1) and implicitly created by the implementation (15.2).

Emphasis added. Note that section 15.2 is [class.temporary]: the rules for temporary objects.

Therefore, we can conclude that temporary objects have storage durations. And we can conclude that temporaries must have one of those storage durations. Indeed, there are numerous references in the standard to "variables or temporary objects" and their storage durations.

However, despite this clearly saying that temporary objects have one of those storage durations... the standard never actually says what storage duration they have. [class.temporary] does not have a statement saying that temporaries bound to references have the storage duration of their references. And [basic.stc]'s explanation of static, automatic, and thread-local durations always speaks of variables.

So I would say that this is a defect in the wording. It seems clear that the standard expects temporaries to have an appropriate storage duration; there are multiple places where the standard talks about the storage duration of variable or temporary objects. But it never says what storage duration they actually have.

So could we improve the situation?

@jensmaurer
Copy link
Member

Duplicate of #4840.

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

2 participants