I know that when passing an object by value to a function, the move constructor is always called if there is one, assuming no copy elision. What about returning an object by value?
For example, say we have a class Foo
which has a move constructor, and we have a function that returns a Foo
object.
Foo g() {
Foo f;
// do something with f
return f;
}
If we assume there is no RVO, is the move constructor guaranteed to be called?
Update: I guess I didn't show my intention clearly. I just want to know I can in the worst case have the object moved not copied. Either RVO or NRVO happens, I am happy. And I should also say that move constructor and move assignment are not deleted and are properly implemented.
f
into the function:return do_something(f);
. – GManNickG