However, the object to which the pointers point seems to live on after the function returns.
The key thing here is "seems to". Actually, the Entry
's lifetime ends at the end of this line:
std::unique_ptr<Entry>{e_ptr}->name_ += " Doe";
The unique_ptr
has taken ownership of the memory, but the temporary unique_ptr
's lifetime ends at the end of that statement, so it also deletes the Entry
that it owns. Accessing memory that was formerly used by the object is undefined behavior. That it works on some platforms and not others is just the nature of undefined behavior.