Why is unique_ptr not equality_comparable_with nullptr_t in C++20?
23:30 03 Apr 2021

Working with C++20's concepts I noticed that std::unique_ptr appears to fail to satisfy the std::equality_comparable_with concept. From std::unique_ptr's definition, it is supposed to implement the following when in C++20:

template
bool operator==(const unique_ptr& x, const unique_ptr& y);

template 
bool operator==(const unique_ptr& x, std::nullptr_t) noexcept;

This requirement should implement symmetric comparison with nullptr -- which from my understanding is sufficient for satisfying equality_comparable_with.

Curiously, this issue appears to be consistent on all the major compilers. The following code is rejected from Clang, GCC, and MSVC:

// fails on all three compilers
static_assert(std::equality_comparable_with,std::nullptr_t>);

Try Online

However the same assertion with std::shared_ptr is accepted:

// succeeds on all three compilers
static_assert(std::equality_comparable_with,std::nullptr_t>);

Try Online

Unless I'm misunderstanding something, this appears to be a bug. My question is whether this is a coincidental bug in the three compiler implementations, or is this a defect in the C++20 standard?

Note: I'm tagging this in case this happens to be a defect.

c++ language-lawyer c++20 c++-concepts