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

### 3426. `operator<=>(const unique_ptr<T, D>&, nullptr_t)` can't get no satisfaction

Section: 20.11.1.6 [unique.ptr.special] Status: WP Submitter: Jonathan Wakely Opened: 2020-04-09 Last modified: 2020-11-09

Priority: 0

View all other issues in [unique.ptr.special].

View all issues with WP status.

Discussion:

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.

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

[2020-04-18 Issue Prioritization]

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

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

Proposed resolution:

This wording is relative to N4861.

1. Modify 20.10.2 [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 20.11.1.6 [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))`.