The compiler can freely copy and move the construct, even if they have side effects, for the objects that it creates on its behalf. Temporary objects and return values ββare often directly built in the right place, speeding up their copying or moving. For return values, you need to be a little careful to be able to execute an ellipse.
If you want to exclude copying, you need to conditionally return two candidate objects:
bool flag(false); A f() { A a; return flag? A(): a; }
Assuming you don't change the flag , this will always create a copy of a (unless the compilers have become smarter since the last time I tried).
source share