OK, so first some things that might be relevant:
I\'m using the Clang 3.1 compiler, in C++11 mode, with the standard library set to libc++.
I\'m trying to fa
The observed behavior is in accordance with the standard.
For unique_ptr, 20.7.1.2.2/2 (destructor effects) says
Effects: If
get() == nullptrthere are no effects. Otherwiseget_deleter()(get()).
For shared_ptr, 20.7.2.2.2/1 says that the deleter should be called even if it wraps the null pointer:
Effects:
- If *this is empty or shares ownership with another
shared_ptrinstance (use_count() > 1), there are no side effects.- Otherwise, if *this owns an object
pand a deleterd,d(p)is called.- Otherwise, *this owns a pointer
p, anddelete pis called.
The important detail here is the expression "owns an object p". 20.7.2.2/1 says that "a shared_ptr object is empty if it does not own a pointer". 20.7.2.2.1/9 (the relevant constructor) says that it "constructs a shared_ptr object that owns the object p and the deleter d".
So as far as I can tell, that invocation technically makes the shared_ptr own the null pointer, which results in the deleter being called. Contrast this with the parameterless constructor which is said to leave the shared_ptr "empty".