This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.
shared_ptr
of function typeSection: 20.3.2.2 [util.smartptr.shared] Status: C++20 Submitter: Agustín K-ballo Bergé Opened: 2017-09-13 Last modified: 2021-02-25
Priority: 3
View all other issues in [util.smartptr.shared].
View all issues with C++20 status.
Discussion:
shared_ptr
has been designed to support use cases where it owns a pointer to function, and whose deleter
does something with it. This can be used, for example, to keep a dynamic library loaded for as long as their exported
functions are referenced.
T
in shared_ptr<T>
can be a function type. It isn't
immediately obvious from the standard, and it's not possible to tell from the wording that this is intentional.
[2017-11 Albuquerque Wednesday night issues processing]
Priority set to 3
Previous resolution [SUPERSEDED]:
This wording is relative to N4687.
Edit 20.3.2.2 [util.smartptr.shared] as indicated:
[…]
-2- Specializations ofshared_ptr
shall beCopyConstructible
,CopyAssignable
, andLessThanComparable
, allowing their use in standard containers. Specializations ofshared_ptr
shall be contextually convertible tobool
, allowing their use in boolean expressions and declarations in conditions.The template parameter-?- The template parameterT
ofshared_ptr
may be an incomplete type.T
ofshared_ptr
may be an incomplete type.T*
shall be an object pointer type or a function pointer type. […]
[2020-02-13; Prague]
LWG would prefer to make the new constraint a Mandates-like thing.
Original resolution [SUPERSEDED]:
This wording is relative to N4849.
Edit 20.3.2.2 [util.smartptr.shared] as indicated:
[…]
-2- Specializations ofshared_ptr
shall be Cpp17CopyConstructible, Cpp17CopyAssignable, and Cpp17LessThanComparable, allowing their use in standard containers. Specializations ofshared_ptr
shall be contextually convertible tobool
, allowing their use in boolean expressions and declarations in conditions.The template parameter-?- The template parameterT
ofshared_ptr
may be an incomplete type.T
ofshared_ptr
may be an incomplete type. The program is ill-formed unlessT*
is an object pointer type or a function pointer type. […]
[2020-02 Friday AM discussion in Prague.]
Marshall provides updated wording; status to Immediate
Proposed resolution:
This wording is relative to N4849.
Edit 20.3.2.2 [util.smartptr.shared] as indicated:
[…]
-2- Specializations ofshared_ptr
shall be Cpp17CopyConstructible, Cpp17CopyAssignable, and Cpp17LessThanComparable, allowing their use in standard containers. Specializations ofshared_ptr
shall be contextually convertible tobool
, allowing their use in boolean expressions and declarations in conditions.The template parameter-?- The template parameterT
ofshared_ptr
may be an incomplete type.T
ofshared_ptr
may be an incomplete type. [Note: T may be a function type. -- end note] […]