710. Missing postconditions

Section: 23.11.3 [util.smartptr.shared] Status: CD1 Submitter: Peter Dimov Opened: 2007-08-24 Last modified: 2016-02-10

Priority: Not Prioritized

View other active issues in [util.smartptr.shared].

View all other issues in [util.smartptr.shared].

View all issues with CD1 status.

Discussion:

A discussion on comp.std.c++ has identified a contradiction in the shared_ptr specification. The shared_ptr move constructor and the cast functions are missing postconditions for the get() accessor.

[ Bellevue: ]

Move to "ready", adopting the first (Peter's) proposed resolution.

Note to the project editor: there is an editorial issue here. The wording for the postconditions of the casts is slightly awkward, and the editor should consider rewording "If w is the return value...", e. g. as "For a return value w...".

Proposed resolution:

Add to 23.11.3.1 [util.smartptr.shared.const]:

shared_ptr(shared_ptr&& r);
template<class Y> shared_ptr(shared_ptr<Y>&& r);

Postconditions: *this shall contain the old value of r. r shall be empty. r.get() == 0.

Add to 23.11.3.9 [util.smartptr.shared.cast]:

template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r);

Postconditions: If w is the return value, w.get() == static_cast<T*>(r.get()) && w.use_count() == r.use_count().

template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r);

Postconditions: If w is the return value, w.get() == dynamic_cast<T*>(r.get()).

template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r);

Postconditions: If w is the return value, w.get() == const_cast<T*>(r.get()) && w.use_count() == r.use_count().

Alberto Ganesh Barbati has written an alternative proposal where he suggests (among other things) that the casts be respecified in terms of the aliasing constructor as follows:

Change 23.11.3.9 [util.smartptr.shared.cast]:

-2- Returns: If r is empty, an empty shared_ptr<T>; otherwise, a shared_ptr<T> object that stores static_cast<T*>(r.get()) and shares ownership with r. shared_ptr<T>(r, static_cast<T*>(r.get()).

-6- Returns:

-10- Returns: If r is empty, an empty shared_ptr<T>; otherwise, a shared_ptr<T> object that stores const_cast<T*>(r.get()) and shares ownership with r. shared_ptr<T>(r, const_cast<T*>(r.get()).

This takes care of the missing postconditions for the casts by bringing in the aliasing constructor postcondition "by reference".