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]

Re: Not Const Temporaries


Hello,

Thank you for your answer,

Alexandre Oliva wrote:
> 
> I see.  The additional member function seems to be preventing the
> return-value optimization.  I assume you're compiling this with
> sufficient optimization to get TKeeped::This)() inlined, right?
Not really : i compiled it whithout any flags (g++ -o test test.cc) and
I was compiling it (old gcc...) with debug on (-g).

> 
> Seems like you're going to have to introduce const copy-constructors
> to avoid the extra copying.
This way works perfectly but leads to an awfull :
static TKeeped &DeConst(const TKeeped &_keeped) { return *(TKeeped *)
&_keeped; }

And i fear that this way can be more dangerous than having a not const
reference to a temporary object.

BTW, I still do not understand how I can not have a const reference to a
temporary but a can call a non const method on it... :-)

Regards,
-- 
                                   \|/      Philippe Cizaire
                                  (o o)       
 . ..  .. -  --  ----  ==  ===oOO==(_)==OOo===  ==  ----  --  - ..  .. .
  High speed, Plug And Play,                pci@silicomp.com
 WWW KoMpAtIbLe, Java++, FT,   .ooo0 0ooo.  Tel. +33 687 74 54 54  
 CORBA 5.9 Compliant and more  (   ) (   )  Fax. +33 476 41 66 67
   .  ..   ...  -  ---  ==  ====\ (===) /====  ==  ---  -  ...   ..  .
                                 \_) (_/


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