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
The rule is that whenever copy elision is allowed but does not occur, the move constructor will be used if it is available, and otherwise the copy constructor will be used.
The exact behaviour is defined by [class.copy]/32:
When the criteria for elision of a copy operation are met or would be met save for the fact that the source object is a function parameter, and the object to be copied is designated by an lvalue, overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If overload resolution fails, or if the type of the first parameter of the selected constructor is not an rvalue reference to the object’s type (possibly cv-qualified), overload resolution is performed again, considering the object as an lvalue.