In my question, only one article is already known to me, in which the application of NRVO is somehow described. Article from MSDN: Named Return Value Optimization in Visual C++ 2005 . However, I am confused by the year of writing this article and the question appears: What is the current state of affairs? After all, the yard is not 2005, and the 2016th!
This article agrees three reasons when it does not work:
- Different Paths Returning Different Named Objects.
- Multiple Return Paths (Even If The Same Named Object IS Returned On All Paths) With an eh states introduced.
- The Named Object Returned Is Referenced in An Inline ASM Block.
Did anyone have changed since then?
Answer 1, Authority 100%
Since the time, only MOVE-seventika has been added, respectively, it became more optimal ways to return from the function by values.
On the other hand, now forced STD :: MOVE ()
can prevent NVRO application. Here I do not know what is better: to keep MOVE
and is guaranteed to get moving, or remove, but get options: NVRO, Move or copy.
look good in the bug trackers of compilers. For example GCC:
- https://gcc.gnu.org/bugzilla/show_bug.cgi? id = 53637
- https://gcc.gnu.org/bugzilla/show_bug.cgi? id = 58051
- https://gcc.gnu.org/bugzilla/show_bug.cgi? id = 58055
on dynamics (especially links 1 and 3), there is a feeling (NVRO appeared in GCC 3.1: https://gcc.gnu.org/gcc-3.1/changes.html ), which is not very raised.
In the first bug there is a reference to an interesting study, a fairly new (updated somewhere in August 2015, according to the GCC version of the trunk), on checking different compilers in excess copying optimization capabilities: http://www.byte-physics.de/cpp-copy-elision .