About safe operations involving unique pointers : <p>Consider the following code:</p>

<pre><code>#include &lt;memory&gt;

struct Foo { std::unique_ptr&lt;Foo&gt; next; };
void f(Foo &amp;foo) { foo = std::move(*foo.next); }

int main() {
    Foo foo{};
    foo.next = std::make_unique&lt;Foo&gt;();
    foo.next-&gt;next = std::make_unique&lt;Foo&gt;();
    f(foo);
}
</code></pre>

<p>By doing <code>foo = std::move(*foo.next);</code>, <code>foo.next.next</code> is moved to <code>foo.next</code>.<br>
If <code>foo.next</code> is invalidated as a first step, the object to which it points could be deleted immediately. This would lead to the deletion of <code>foo.next.next</code>, that is the object that I'm trying to move to <code>foo.next</code>.<br>
I'm pretty sure I'm missing something in my reasoning, but I can't figure out what's wrong.<br>
Is it a safe operation? Where does the standard reassure me about that?</p>
