I've read about unique_ptr with incomplete types and about Checked Delete. But is checked-delete obsolete when using smart pointers, or at least a subset of C++11's smart pointers?
Take the following code:
class A;
class B
{
public:
std::auto_ptr<A> autoPtr;
std::unique_ptr<A> uniquePtr;
std::shared_ptr<A> sharedPtr;
A* rawPtr;
B();
~B(){delete rawPtr;}
};
class A
{
public:
~A(){std::cout << "~A" << std::endl;}
};
B::B()
{
autoPtr = std::auto_ptr<A>(new A());
uniquePtr = std::unique_ptr<A>(new A());
sharedPtr = std::shared_ptr<A>(new A());
rawPtr = new A();
}
B b;
When B's destructor is defined, the type of A is still incomplete. As far as I know [C++11 standard @ [expr.delete]] the deletion of the raw pointer is undefined behaviour. On my machine, gcc 4.8 shows some warnings about this but compiles and the A's destructor is not called appropriately.
But what about the smart pointers? As I've read, unique_ptr and shared_ptr must work according to the c++11 standard. But both linked documents state, that auto_ptr won't work. But at least with my gcc 4.8 also auto_ptr correctly calls the destructor, without any warning. Is this still undefined behaviour and gcc is just nice?
In short: Which of the four member variables are guaranteed to destroy their A-pointer appropriately using it's later defined destructor, according to the C++11 standard?
And finally: If I only use unique_ptr and shared_ptr and never call "delete" by myself, am I safe and never need to think about "checked delete" again?