Someone correct me if I am wrong but isn't that last snippet where he returns std::move(localObj) essentially returning an rvalue-ref to a local object? That's like a big no-no because the local object destructs after foo(1) returns.
constructor.
destructor.
move constructor
destructor.
i.e. the data destructed before it was moved.> Note: We should not use this way in the real development, because it is a reference to a local object. Here just show how to make RVO happened.
I'm struggling to see how it's an appropriate use of std::move in any case where you actually use the rvalue reference!