3 ms·
Returning a stack allocated value is a move in C++11/14. It is also true that in many circumstances a compiler may optimize that move away using RVO/NRVO. Cons
by detrino 10y ago
Returning a stack allocated value is a move in C++11/14. It is also true that in many circumstances a compiler may optimize that move away using RVO/NRVO.
Consider this example: http://ideone.com/T872Oj http://ideone.com/T872Oj
In F1 the compiler can NRVO away the move.
In F2 it cannot.
Both will fail to compile if you delete the move constructor.
- poizan42 10y agoDoes that mean that side effects in a move constructor is undefined behavior since you can't know whether it's going to be called? Edit: I see that StephanTLavavej clarified that below.