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
Yes it is the correct behavior.
§20.7.1.2.2[unique.ptr.single.dtor]/2:
unique_ptrdestructorEffects: If
get() == nullptrthere are no effects. Otherwiseget_deleter()(get()).
§20.7.2.2.2[util.smartptr.shared.dest]/1:
shared_ptrdestructorEffects:
- If
*thisis empty or shares ownership with anothershared_ptrinstance (use_count() > 1), there are no side effects.- Otherwise, if
*thisowns an objectpand a deleterd,d(p)is called.- Otherwise,
*thisowns a pointerp, and deletepis called.
So there should be no effect since the shared_ptr is empty? Wrong, because providing the a pointer makes the shared_ptr not empty, even if the pointer is null.
§20.7.2.2.1[util.smartptr.shared.const]/8–10
shared_ptrconstructorstemplateshared_ptr(Y* p, D d); template shared_ptr(Y* p, D d, A a); template shared_ptr(nullptr_t p, D d); template shared_ptr(nullptr_t p, D d, A a); Requires:
pshall be convertible toT*. …Effects: Constructs a
shared_ptrobject that owns the objectpand the deleterd.Postconditions:
use_count() == 1 && get() == p.
This means the shared_ptr owns the nullptr. Thus the deleter will be called when the shared_ptr is destroyed.