Doing std::move twice with the same unique_ptr
Moving from a unique_ptr
leaves it as null. So baz
will end up being null too.
Essentially, nothing. The standard library requires that moving a library type leaves it in a valid but unspecified state. By valid they mean you can still do things to the object that don't require a precondition. That would be things like assigning it a new value or destroying it. For unique_ptr
we actually get more of a guarantee of the state as the move constructor guarantees that the moved from object is set to nullptr
. That means in the end of all of this bar
holds the pointer and foo
and baz
are both nullptr
.