@
mooncakejs #10
编译器开优化也要讲基本法的。
http://en.cppreference.com/w/cpp/language/copy_elisionWhen a **NAMELESS** temporary, not bound to any references, would be copied or moved (since C++11) into an object of the same type (ignoring top-level cv-qualification), the copy/move (since C++11) is omitted. When that temporary is constructed, ** it is constructed directly in the storage where it would** otherwise be copied or moved (since C++11) to. When the nameless temporary is the argument of a return statement, this variant of copy elision is known as RVO, "return value optimization".
NAMELESS 的意思懂吧?就是不能绑定到任何一个变量名(否则就变成了左值了)
如果像你说的,没有东西能碰 v 就能 RVO,那编译器怎么知道 v 里面的不会被其他对象访问?
只要有变成左值的机会,就无法消除这个可能。