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

### 2873. Add `noexcept` to several `shared_ptr` related functions

Section: 20.11.3 [util.smartptr.shared] Status: C++17 Submitter: United States Opened: 2017-02-03 Last modified: 2020-09-06

Priority: Not Prioritized

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

View all issues with C++17 status.

Discussion:

Addresses US 124

Several `shared_ptr` related functions have wide contracts and cannot throw, so should be marked unconditionally `noexcept`.

Proposed change:

Add `noexcept` to:

>     template<class U>
>     bool
>     shared_ptr::owner_before(shared_ptr<U> const& b) const noexcept;

>     template<class U>
>     bool
>     shared_ptr::owner_before(weak_ptr<U> const& b) const noexcept;

>     template<class U>
>     bool
>     weak_ptr::owner_before(shared_ptr<U> const& b) const noexcept;

>     template<class U>
>     bool
>     weak_ptr::owner_before(weak_ptr<U> const& b) const noexcept;

>     bool owner_less::operator()(A,B) const noexcept; // all versions

[2017-02-20, Marshall adds wording]

[Kona 2017-02-27]

Accepted as Immediate to resolve NB comment.

Proposed resolution:

This wording is relative to N4640.

1. Modify 20.11.3 [util.smartptr.shared] as indicated:

   >       template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
   >       template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;

2. Modify 20.11.3.6 [util.smartptr.shared.obs] as indicated:

   >     template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
   >     template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;

3. Modify 20.11.5 [util.smartptr.ownerless] as indicated:

   >     template<class T> struct owner_less<shared_ptr<T>> {
   >        bool operator()(const shared_ptr<T>&, const shared_ptr<T>&) const noexcept;
   >        bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const noexcept;
   >        bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const noexcept;
   >     };

   >     template<class T> struct owner_less<weak_ptr<T>> {
   >        bool operator()(const weak_ptr<T>&, const weak_ptr<T>&) const noexcept;
   >        bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const noexcept;
   >        bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const noexcept;
   >     };

   >     template<> struct owner_less<void> {
   >        template<class T, class U>
   >           bool operator()(const shared_ptr<T>&, const shared_ptr<U>&) const noexcept;
   >        template<class T, class U>
   >           bool operator()(const shared_ptr<T>&, const weak_ptr<U>&) const noexcept;
   >        template<class T, class U>
   >           bool operator()(const weak_ptr<T>&, const shared_ptr<U>&) const noexcept;
   >        template<class T, class U>
   >           bool operator()(const weak_ptr<T>&, const weak_ptr<U>&) const noexcept;
   >        using is_transparent = unspecified;
   >     };