TITLE: New ruling on lifetime of temporaries (part II) PROBLEM: 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) Out of date. A temporary lasts to "end of full expression", which is usually the end of the statement. RESPONSE: ehsjony@ehs.ericsson.se !!!! Usually ? :-) Does somebody know if there is a formal definition for the life-time which can be reasonably easily understood. When this new rule for temporaries was introduced I read some explanations on the net but never quite managed to grasp this rule. RESPONSE: maxtal@physics.su.OZ.AU (John Max Skaller), 12 Jan 95 There are two exceptions. 1) A non-parameter non-class const reference bound to a temporary has the duration of the reference (static or automatic). For example: void f() { const int & i = 1; int j= i; // fine, "i" still exists } 2) A temporary used in a || or && or as the first argument in a ?: expression or conditional dies after it has been evaluated: int* f(int const &a) { return &a; } int* pi; if(pi=f(1)) { cout << *pi; } // error! See the WP12.2/2.