This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Order of Object destruction
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Neophytos Michael <nmichael at cs dot princeton dot edu>, gcc-help at gcc dot gnu dot org
- Date: Fri, 23 May 2003 07:12:10 -0500
- Subject: Re: Order of Object destruction
Hi Neophytos,
Yes, the order of destruction is specified, due in no small part to the
lifespan of a temporary being well-defined.
Effectively, the temporary object lives until the end-of-statement semicolon.
As I understand it (I've never needed to tried this), if there were an
alias to it, it would live until the end of the extant of alias. For example:
A a;
A& b = foo(a);
// a and b are live.
cout << a.y << endl;
cout << b.y << endl; // Okay.
Before the standard's committee nailed the issue, compiler vendors were
inconsistent when the temporary object was destructed. Which lead to all
sorts of non-portable code and frustrated programmers.
--Eljay