Not only never necessary, but a bad idea on function return (it may inhibit copy elision / RVO)
Seems like you're right.
See also "Moving from lvalues" and "Moving out of functions" here:
http://stackoverflow...11540204/859774
Very good explanation.
return C;
return Matrix(C);
These should call the copy constructor (in debug build with all optimizations off)
Ah this was wrong. C++ standard has special rule:
[quote name='§12.8 [class.copy] p32']
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. [ Note: This two-stage overload resolution must be performed regardless of whether copy elision will occur. It determines the constructor to be called if elision is not performed, and the selected constructor must be accessible even if the call is elided.
[/quote]
This means it will first try to move, and then copy. I wonder if copy constructor has side effects, it might bite someone.