TITLE: New ruling on lifetime of temporaries PROBLEM: walz@lamisun3.epfl.ch (Michael Walz) I wonder how long is the lifetime of temporary objects created by the compiler in C++. RESPONSE: Viktor Yurkovsky According to the ARM, the lifetime of temporary objects is implementation-dependent. Therefore, you should not rely on the existance of temporary objects beyond their normal function of assignment. RESPONSE: maxtal@physics.su.OZ.AU (John Max Skaller), Mon Jan 9 Out of date. A temporary lasts to "end of full expression", which is usually the end of the statement. RESPONSE: fjh@munta.cs.mu.OZ.AU (Fergus Henderson), 8 Jan 95 Generally, they last until the end of their containing expression. The exception is when they are used to initialize a reference, i.e. const T& r = temporary(); in which case the temporary's lifetime is the same as that of the reference. Yes, that's true [the ARM saying its implementation dependent], but the ANSI/ISO C++ committee changed the rules. It is no longer implementation-dependant. However, compilers are still catching up, and so if you want to write portable code, you should not depend on the new rules. [...]