813. "empty" undefined for shared_ptr

Section: 23.11.3 [util.smartptr.shared] Status: CD1 Submitter: Matt Austern Opened: 2008-02-26 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.


Several places in 23.11.3 [util.smartptr.shared] refer to an "empty" shared_ptr. However, that term is nowhere defined. The closest thing we have to a definition is that the default constructor creates an empty shared_ptr and that a copy of a default-constructed shared_ptr is empty. Are any other shared_ptrs empty? For example, is shared_ptr((T*) 0) empty? What are the properties of an empty shared_ptr? We should either clarify this term or stop using it.

One reason it's not good enough to leave this term up to the reader's intuition is that, in light of N2351 and issue 711, most readers' intuitive understanding is likely to be wrong. Intuitively one might expect that an empty shared_ptr is one that doesn't store a pointer, but, whatever the definition is, that isn't it.

[ Peter adds: ]

Or, what is an "empty" shared_ptr?

Alisdair's wording is fine.

Proposed resolution:

Append the following sentance to 23.11.3 [util.smartptr.shared]

The shared_ptr class template stores a pointer, usually obtained via new. shared_ptr implements semantics of shared ownership; the last remaining owner of the pointer is responsible for destroying the object, or otherwise releasing the resources associated with the stored pointer. A shared_ptr object that does not own a pointer is said to be empty.