This is the mail archive of the gcc@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]

Re: c++ warning idea


On Sep 17, 1999, paulf@metaip.checkpoint.com wrote:

>  Foo GiveAFoo();
>  const Foo& rfoo = GiveAFoo();

> What happens is a temporary Foo object is returned, a reference to it
> stored, and the temporary object destructed, ending up with the equivalent
> of an uninitialized pointer.

> It is, in fact, pointless to initialize a reference to a temporary, but
> there are less than obvious ways where this can be accidentally done.

Nope, when a reference is bound to a temporary, the temporary will
remain at least until the reference itself goes out of scope.
[class.temporary]/5

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them


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