2 ms·
unique_ptr doesn't have any aliasing guarantees, unique_ptr::get() will happily hand out references to the interior pointer. It does give you non-ambiguous own
by vvanders 4y ago
unique_ptr doesn't have any aliasing guarantees, unique_ptr::get() will happily hand out references to the interior pointer.
It does give you non-ambiguous ownership semantics which is a good thing but there's still plenty of ways to misuse/abuse it.
That said if you can make the aliasing guarantees(such as Rust's borrow checker does) that opens up the possibility of automatically applying restrict semantics[1] which enables further set of optimizations available to the compiler.
[1] https://en.cppreference.com/w/c/language/restrict https://en.cppreference.com/w/c/language/restrict
- zamalek 4y agoThere's a lot of UB in that spec. Are compilers capable of warning/erroring UB in this case?