This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]