[Bug c++/47026] invalid temporary is being assigned to a const-reference

2010-12-20 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47026

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID

--- Comment #2 from Jonathan Wakely  2010-12-20 
12:03:12 UTC ---
(In reply to comment #0)
> 
> /* temporary is being assigned to a const-reference : BAD */
> const int* const &alias(ptr);

This is the correct behaviour, see 12.2 [class.temporary] paragraphs 4 and 5 in
the standard:

"4 There are two contexts in which temporaries are destroyed at a different
point than the end of the full-expression. ...
"5 The second context is when a reference is bound to a temporary. The
temporary to which the reference is bound or the temporary that is the complete
object to a subobject of which the temporary is bound persists for the lifetime
of the reference except as specified below."

The lifetime of the temporary ends on return from main, so the temporary also
ends when main returns.


[Bug c++/47026] invalid temporary is being assigned to a const-reference

2010-12-20 Thread tmoschou at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47026

Terry  changed:

   What|Removed |Added

 CC||tmoschou at gmail dot com

--- Comment #1 from Terry  2010-12-20 11:33:37 UTC 
---
Whoops, forgot to say compiled on Ubuntu 10.10 x64.