3018. shared_ptr of function type

Section: 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.

Implementations have overlooked that the 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.

  1. Edit 20.3.2.2 [util.smartptr.shared] as indicated:

    […]

    -2- Specializations of shared_ptr shall be CopyConstructible, CopyAssignable, and LessThanComparable, allowing their use in standard containers. Specializations of shared_ptr shall be contextually convertible to bool, allowing their use in boolean expressions and declarations in conditions. The template parameter T of shared_ptr may be an incomplete type.

    -?- The template parameter T of shared_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.

  1. Edit 20.3.2.2 [util.smartptr.shared] as indicated:

    […]

    -2- Specializations of shared_ptr shall be Cpp17CopyConstructible, Cpp17CopyAssignable, and Cpp17LessThanComparable, allowing their use in standard containers. Specializations of shared_ptr shall be contextually convertible to bool, allowing their use in boolean expressions and declarations in conditions. The template parameter T of shared_ptr may be an incomplete type.

    -?- The template parameter T of shared_ptr may be an incomplete type. The program is ill-formed unless T* 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.

  1. Edit 20.3.2.2 [util.smartptr.shared] as indicated:

    […]

    -2- Specializations of shared_ptr shall be Cpp17CopyConstructible, Cpp17CopyAssignable, and Cpp17LessThanComparable, allowing their use in standard containers. Specializations of shared_ptr shall be contextually convertible to bool, allowing their use in boolean expressions and declarations in conditions. The template parameter T of shared_ptr may be an incomplete type.

    -?- The template parameter T of shared_ptr may be an incomplete type. [Note: T may be a function type. -- end note]

    […]