[Bug c++/57207] Incorrect lifetime of const references bound to temporary

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 8 11:30:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57207

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-05-08 11:30:43 UTC ---
(In reply to comment #0)
> Why const reference to temporary object (List) does not prolong life time of
> temporary object (TByteArrayList() << TMyStruct())?

Because (TByteArrayList() << TMyStruct()) is not a temporary object, it's a
reference returned by operator<<

The temporary object is TByteArrayList() and that is bound to the reference
parameter of operator<< not to List, so as comment 1 says, the temporary does
not have its lifetime extended.

G++ is correct.



More information about the Gcc-bugs mailing list