2365. Missing noexcept in shared_ptr::shared_ptr(nullptr_t)

Section: 23.11.3 [util.smartptr.shared] Status: C++17 Submitter: Cassio Neri Opened: 2014-02-13 Last modified: 2017-07-30

Priority: Not Prioritized

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

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

View all issues with C++17 status.


The declaration and definition of shared_ptr::shared_ptr(nullptr_t), given in 23.11.3 [util.smartptr.shared], is

constexpr shared_ptr(nullptr_t) : shared_ptr() { }

The intention seems clear: this constructor should have the same semantics of the default constructor. However, contrarily to the default constructor, this one is not noexcept. In contrast, unique_ptr::unique_ptr(nullptr_t) is noexcept, as per [unique.ptr.single]:

constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }

Both libstdc++ and libc++ have added noexcept to shared_ptr::shared_ptr(nullptr_t). Microsoft's STL has not.

[2014-03-26 Library reflector vote]

The issue has been identified as Tentatively Ready based on six votes in favour.

Proposed resolution:

This wording is relative to N3936.

  1. Change class template shared_ptr synopsis, 23.11.3 [util.smartptr.shared], as indicated:

    constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }