Feb 16, 2016

[RVO] Details

Conditions for RVO:
iff
(1) the type of the local object is the same as that returned by the function and 
(2) the local object  (i.e not rvalue, but l-value local object is what's being returned.



If the conditions for the RVO are met,
but compilers choose not to perform copy elision, 
the object being returned must be treated as an rvalue.

The situation is similar for by-value function parameters.
They’re not eligible for copy elision with respect to their function’s return value,
but compilers must treat them as rvalues if they’re returned.


clang/g++ command to avoid RVO:

-fno-elide-constructors

reference:
http://stackoverflow.com/questions/13099603/c11-move-constructor-not-called-default-constructor-preferred/13099664#13099664

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.