Title
operator<=>(const shared_ptr<T>&, nullptr_t) definition ill-formed
Status
c++23
Section
[util.smartptr.shared.cmp]
Submitter
Daniel Krügler

Created on 2020-04-11.00:00:00 last changed 5 months ago

Messages

Date: 2020-11-09.21:40:50

Proposed resolution:

This wording is relative to N4861.

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

    template<class T>
      strong_ordering operator<=>(const shared_ptr<T>& a, nullptr_t) noexcept;
    

    -5- Returns: compare_three_way()(a.get(), static_cast<typename shared_ptr<T>::element_type*>(nullptr)).

Date: 2020-11-09.00:00:00

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

Date: 2020-05-16.00:00:00

[ 2020-05-16 Reflector discussions ]

Status to Tentatively Ready and priority to 0 after five positive votes on the reflector.

Date: 2020-04-11.00:00:00

This is similar to LWG 3426: This time the definition of operator<=>(const shared_ptr<T>&, nullptr_t) is ill-formed, whose effects are essentially specified as calling:

compare_three_way()(a.get(), nullptr)

This call will be ill-formed by constraint-violation, because both nullptr <=> nullptr as well as ((T*) 0) <=> nullptr are ill-formed.

As a short-term solution we can make it work as intended — equivalent to LWG 3426 — by comparing a.get() to (element_type*) nullptr instead of to nullptr directly.

As a long-term solution we should at least consider to deprecate the mixed relational operators as well as the mixed three-way comparison operator of all our smart-pointers with std::nullptr_t since the core language has eliminated relational comparisons of pointers with std::nullptr_t with N3624 four years after they had been originally accepted by CWG 879. Consequently, for C++20, the mixed three-way comparison between pointers and nullptr is not supported either. For this long-term solution I'm suggesting to handle this via a proposal.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2020-11-09 21:40:50adminsetmessages: + msg11571
2020-11-09 21:40:50adminsetstatus: ready -> wp
2020-05-16 16:57:58adminsetmessages: + msg11297
2020-05-16 16:57:58adminsetstatus: new -> ready
2020-04-11 17:58:32adminsetmessages: + msg11211
2020-04-11 00:00:00admincreate