The C++ standards do not specify the storage duration of temporary objects. This is the subject of CWG issue 1634.
According to the linked site, the status of this issue is "drafting", which means:
Drafting: Informal consensus has been reached in the working group and is described in rough terms in a Tentative Resolution, although precise wording for the change is not yet available.
However there is no explicit mention of a consensus/resolution for this particular issue and I was also not able to find it anywhere else on the committee's site.
I guess that the consensus is that lifetime-extended temporaries should have storage duration equal to that of the reference they are bound to, but it is less clear for non-lifetime-extended temporaries.
In particular it is not clear to me whether a temporary created in a statement at block-scope would have (automatic?) storage duration extending to the end of the block, like an automatic variable declared at the same point would have, or whether its storage duration ends with its (default) lifetime at the end of the full-expression. The issue description hints at the latter being the case.
Is the description supposed to contain the "Tentative Resolution" and if so did I interpret is correctly or if not, can I find the "Tentative Resolution" of this issue somewhere else?
In addition, do the major compilers currently follow this consensus, either in a documented manner or de-facto?
See also older questions:
- What is a temporary object with static storage duration
- What's the requirement for storage duration of temporaries?
- Where are temporary object stored?
Edit for clarification:
I am not asking about the lifetime of the temporary, that is well-specified in the standard. I am asking about the storage duration. For example:
#include<new>
struct A {
operator A*() {
return this;
}
int i = 0;
// Some other stuff (and non-trivial destructor)
};
A* ptr1 = A();
A* ptr1_new = new(ptr1) A();
// Use new object through ptr1_new
A* ptr2 = A();
int main() {
A* ptr2_new = new(ptr2) A();
A* ptr3 = A();
A* ptr3_new = new(ptr3) A();
// Use new objects through ptr2_new and ptr3_new
}
The question is whether the standard (committee) intends these placement-news to be well-defined or undefined behavior. After having thought about it for a while, I suppose that probably the intention is that all of them are undefined behavior, but I wanted to get a clear answer.
Another aspect is that the standard often refers to "objects of static/automatic/thread/dynamic storage duration" and that temporaries are objects, but without specification on how to determine to which of these four classes they belong.