This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

813. "empty" undefined for shared_ptr

Section: 20.3.2.2 [util.smartptr.shared] Status: CD1 Submitter: Matt Austern Opened: 2008-02-26 Last modified: 2016-01-28

Priority: Not Prioritized

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

View all issues with CD1 status.

Discussion:

Several places in 20.3.2.2 [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(i), 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 20.3.2.2 [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.