From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-10-13 12:19:17
>From: "Gabriel Dos Reis" <gdr_at_[hidden]>
>Terje Slettebø <tslettebo_at_[hidden]> writes:
>| Could someone point me to the part of the standard that allows for RVO
Thanks. :) It says:
"Whenever a temporary class object is copied using a copy constructor, and
this object and the copy have the same cv-unqualified type, an
implementation is permitted to treat the original and the copy as two
different ways of referring to the same object and not perform a copy at
all, even if the class copy constructor or destructor have side effects. For
a function with a class return type, if the expression in the return
statement is the name of a local object, and the cv-unqualified type of the
local object is the same as the function return type, an implementation is
permitted to omit creating the temporary object to hold the function return
value, even if the class copy constructor or destructor has side effects. In
these cases, the object is destroyed at the later of times when the original
and the copy would have been destroyed without the optimization."
It appears from this that RVO and NRVO are treated in the same way - both
are allowed to elide copying, even if the copy would have a side effect.
>From this, as mentioned in another posting, could this also hold for a value
parameter (it's a local object, as well)? I.e. like the following:
inline Test operator+(Test t1,const Test &t2)
return t1; // Can NRVO be applied here?
>From the test I did on Intel C++, it didn't apply the NRVO in this case, but
I'm wondering if the standard would allow it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk