3 ms·
To elide a return copy/move, the compiler has to know at compile time exactly which local variable is going to be returned, so that it can arrange to have that
by kentonv 11y ago
To elide a return copy/move, the compiler has to know at compile time exactly which local variable is going to be returned, so that it can arrange to have that local variable constructed directly into the return location, thus avoiding the need to copy/move it later.
So to elide a copy/move from an rvalue reference, the compiler would have to know at compile time that the rvalue reference always points to some particular local variable.
In theory a compiler could look into the inline definition of std::move() and determine that it always returns a reference to its parameter, but that's a rather involved optimization for the spec to require of all implementations.