When does returning an rvalue reference result in undefined behavior?
问题 In an Stack Overflow answer here, Kerrek posts the following code. Foo && g() { Foo y; // return y; // error: cannot bind ‘Foo’ lvalue to ‘Foo&&’ return std::move(y); // OK type-wise (but undefined behaviour, thanks @GMNG) } GManNickG points out that this results in undefined behavior. Kerrek adds True; you don't really return && from anything but forward and move. It's a contrived example. What confuses me is that the C++11 standard uses a function call that returns an rvalue reference as an