Em qui 08 maio 2014, às 07:32:59, Tomaz Canabrava escreveu:
> Em 08/05/2014 01:52, "Thiago Macieira" <[email protected]> escreveu:
> > QList::first() returns a reference to an item, but that list was a
> > temporary. The list gets destroyed at the end of the statement (the
> > semi-colon), so we ended up keeping a reference to freed data (i.e., a
> > dangling pointer0
> 
> I thought a constant reference keeped the object alive until the end of the
> life of the cost ref.

Only if the returned type was by value. The problem is that QList<T>::first() 
returns const T &., which is a reference to an element in the list. In that 
case, the reference is nothing but a pointer and we get dangling references 
when the QList gets deallocated.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to