C++ Logo

std-proposals

Advanced search

Re: nullptr_t and nullopt_t should both have operator<=> and operator== to enable the *_with concepts

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sat, 10 Jul 2021 08:00:46 +0200
On 10/07/2021 01.24, Nevin Liber via Std-Proposals wrote:
> Current state of the world <https://godbolt.org/z/7vcdMdjTe <https://godbolt.org/z/7vcdMdjTe>>:
>
> char* p = nullptr;
>
> static_cast<void>(p < nullptr); // invalid
> static_cast<void>(std::less<>()(p, nullptr)); // valid on clang 12; invalid on gcc 11
> static_cast<void>(std::less<char*>()(p, nullptr)); // valid
> static_cast<void>(std::unique_ptr<char*>() < nullptr); // valid
> static_cast<void>(std::shared_ptr<char*>() < nullptr); // valid

Ignoring the argument that std::less represents a total order on pointers
(but there is no such thing for raw pointer comparisons), this feels a
bit like the std::string(nullptr) discussion:

We made std::string(nullptr) ill-formed, but std::string((char*)0)
continues to be well-formed (necessarily) and has undefined behavior.

See P2166R1 A Proposal to Prohibit std::basic_string and
std::basic_string_view construction from nullptr,
adopted in the most recent plenary.

Jens

Received on 2021-07-10 01:00:53