I can not decide on the definition of RVO (and NRVO) due to several questions like this , which, it seems to me, suggest that RVO omits the copy constructor. Now according to 12.8.15
In such cases, the implementation considers the source and purpose of the omitted copy operation as just two different ways of accessing the same object, and the destruction of this object occurs in later times, when two objects would have been destroyed without optimization.
It seems that the call to the copy constructor is not omitted, but the copy itself - only the object is first constructed in the place of "copy", so there is no "original" object and no copy at all. Thus, even if the class has a privatecopy constructor , it can be returned from the function when RVO is started because there is no copy.
Did I get it right? Is copying itself lowering or is the call to the copy constructor complete? Should I allow the return of an object from a function if the class of the object has a private copy constructor?
source
share