In the return statement, if you return a local variable, the expression is treated as an rvalue, and thus automatically moved. It is thus similar to:
return std::move(p);
It invokes the unique_ptr(unique_ptr&&)
constructor.
In the main function, bar()
produces a temporary, which is an rvalue, and is also properly moved into the p
in main
.