Title
operator<=>(const unique_ptr<T, D>&, nullptr_t) can't get no satisfaction
Status
c++23
Section
[unique.ptr.special]
Submitter
Jonathan Wakely

Created on 2020-04-09.00:00:00 last changed 12 months ago

Messages

Date: 2020-11-09.21:40:50

Proposed resolution:

This wording is relative to N4861.

  1. Modify [memory.syn] as indicated:

    […]
    template<class T, class D>
      bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
    template<class T, class D>
      requires three_way_comparable_with<typename unique_ptr<T, D>::pointer, nullptr_t>
      compare_three_way_result_t<typename unique_ptr<T, D>::pointer, nullptr_t>
        operator<=>(const unique_ptr<T, D>& x, nullptr_t);
    […]
    
  2. Modify [unique.ptr.special] as indicated:

    template<class T, class D>
      requires three_way_comparable_with<typename unique_ptr<T, D>::pointer, nullptr_t>
      compare_three_way_result_t<typename unique_ptr<T, D>::pointer, nullptr_t>
        operator<=>(const unique_ptr<T, D>& x, nullptr_t);
    

    -18- Returns: compare_three_way()(x.get(), static_cast<typename unique_ptr<T, D>::pointer>(nullptr)).

Date: 2020-11-09.00:00:00

[ 2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready → WP. ]

Date: 2020-04-18.00:00:00

[ 2020-04-18 Issue Prioritization ]

Status set to Tentatively Ready after seven positive votes on the reflector.

Date: 2020-04-15.00:00:00

[ 2020-04-14; Replacing the functional cast by a static_cast as result of reflector discussion ]

Date: 2020-04-09.00:00:00

The constraint for operator<=>(const unique_ptr<T, D>&, nullptr_t) cannot be satisfied, because std::three_way_comparable<nullptr_t> is false, because nullptr <=> nullptr is ill-formed.

We can make it work as intended by comparing x.get() to pointer(nullptr) instead of to nullptr directly.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2020-11-09 21:40:50adminsetmessages: + msg11570
2020-11-09 21:40:50adminsetstatus: ready -> wp
2020-04-18 12:27:44adminsetmessages: + msg11225
2020-04-18 12:27:44adminsetstatus: new -> ready
2020-04-14 17:15:54adminsetmessages: + msg11217
2020-04-09 16:30:25adminsetmessages: + msg11209
2020-04-09 00:00:00admincreate