You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is agreed that the shared_ptr calls the appropriate non-virtual destructor.
struct Base { ~Base() {} } ;
struct Derived : Base { ~Derived() { } } ;
std::shared_ptr<Base> p( new Derived() ) ;
// call Derived's destructor on destruction of p
Current wording cannot be interpreted as such for non-array type.
At [util.smartptr.shared.const], of the constructor:
template<class Y> explicit shared_ptr(Y* p);
Effects clause stated that:
When \tcode{T} is not an array type,
constructs a \tcode{shared_ptr} object
that owns the pointer \tcode{p}.
Otherwise, constructs a \tcode{shared_ptr}
that owns \tcode{p} and a deleter of an
unspecified type that calls \tcode{delete[] p}.
Notice the period at line 3. I interpret this two sentences as follows.
For non-array type T, it just own a pointer and nothing else. It does not own a deleter which conveniently call delete p where type of p is Y *.
For array type T, it own a pointer and a deleter which calls delete[] p where the type of p is Y *.
Since it doesn't own a deleter for non-array type T, the shared_ptr destructor simply calls delete p as stated in [util.smartptr.shared.dest].
\item Otherwise, \tcode{*this} owns a pointer \tcode{p},
and \tcode{delete p} is called.
Destructor's wording simply says p is "a pointer p", it doesn't say what type it is. If this wording is suffice, we can remove a deleter for array type T.
The proposed fix is, change the first sentence of quoted Effects clause as follows.
When \tcode{T} is not an array type,
constructs a \tcode{shared_ptr} object
that owns the pointer \tcode{p} and a deleter of an
unspecified type that calls \tcode{delete p}.
A side note. Non-array type said "owns the pointer `tcode{p}", array type said "owns \tcode{p}". It's inconsistent. It should be consistent.
The text was updated successfully, but these errors were encountered:
EzoeRyou
changed the title
shared_ptr do not own a deleter for non-array pointer
shared_ptr do not own a deleter for non-array type
Dec 4, 2018
It is agreed that the
shared_ptr
calls the appropriate non-virtual destructor.Current wording cannot be interpreted as such for non-array type.
At [util.smartptr.shared.const], of the constructor:
template<class Y> explicit shared_ptr(Y* p);
Effects clause stated that:
Notice the period at line 3. I interpret this two sentences as follows.
T
, it just own a pointer and nothing else. It does not own a deleter which conveniently calldelete p
where type ofp
isY *
.T
, it own a pointer and a deleter which callsdelete[] p
where the type ofp
isY *
.Since it doesn't own a deleter for non-array type
T
, the shared_ptr destructor simply callsdelete p
as stated in [util.smartptr.shared.dest].Destructor's wording simply says
p
is "a pointer p", it doesn't say what type it is. If this wording is suffice, we can remove a deleter for array type T.The proposed fix is, change the first sentence of quoted Effects clause as follows.
A side note. Non-array type said "owns the pointer `tcode{p}", array type said "owns \tcode{p}". It's inconsistent. It should be consistent.
The text was updated successfully, but these errors were encountered: