Dereference of a null pointer is memory-unsafe due to being undefined behavior. 
You can't count on dereference of nullptr resulting in a load of address zero: 
the optimizer is free to (and often does) remove that load and any code 
following it. This means that, for example, clang will cheerfully allow you to 
fall off the end of a function after dereferencing a moved pointer.

Patrick

comex <com...@gmail.com> wrote:
>On Wed, Mar 5, 2014 at 6:22 AM, Michael Neumann <mneum...@ntecs.de>
>wrote:
>> Try the same in C++:
>>
>>
>>     auto i = make_unique<int>(1234);
>>     auto j = std::move(i);
>>     cout << *j << endl; // 1234
>>     cout << *i << endl; // Segmentation Fault
>
>Note that a move out of unique_ptr is guaranteed to leave the original
>null, so while this is not detected at compile time, it's also not
>memory-unsafe.
>_______________________________________________
>Rust-dev mailing list
>Rust-dev@mozilla.org
>https://mail.mozilla.org/listinfo/rust-dev

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to