Sure, other than not actually being safe (UB resulting from use after move of unique_ptr being an obvious one; there are many others).
The lesson of C++ is that you can't bolt on safety by using templates to paper over the underlying mess. The mold always seeps through the wallpaper. The usual problem is that at some point you need raw pointers to call some API. If you can get raw pointers, the abstraction has to have a leak.
Nope, the argument is "valid but unspecified" not necessarily null. And http://en.cppreference.com/w/cpp/utility/move specifically has this as an example of UB:
std::vector<std::string> v;
std::string str = "example";
v.push_back(std::move(str)); // str is now valid but unspecified
str[0]; // undefined behavior: operator[](size_t n) has a precondition size() > n
There's an other fun UB because std::move doesn't check for aliasing, so self-assignment: v = std::move(v);
is also an UB.And of course even if it were null., pcwalton talks about use after null. Deref'ing a null pointer (to use it) is still an UB.
From 20.7.1
Additionally, u can, upon request, transfer ownership to
another unique pointer u2. Upon completion of such a
transfer, the following postconditions hold:
— u.p is equal to nullptr,
unique_ptr isn't what's unsafe here. Null pointers are. The difference, admittedly, is mostly semantic. There is nothing undefined about using a unique_ptr after moving unless you use the internal pointer in undefined ways.If you dereference (i.e. use) a moved unique pointer you get undefined behavior.
When talking about "using a pointer" most people mean dereferencing it, not for example comparing against null. It may be somewhat imprecise language, but it's what security people mean when they talk about "use after free", for example.
Undefined behavior, at least colloquially, is about dereferencing a pointer to memory that may or may not be accessed and may or may not work/crash-the-program. That's what makes it undefined and an absolute disaster to track down.
I'm pretty sure that if you try to deference memory address zero the OS will bark at you.
Again, it's not my area of expertise, so please correct me if I'm wrong
e.g.
- http://stackoverflow.com/q/6793262/1256624
- http://blog.llvm.org/2011/05/what-every-c-programmer-should-...