On Thu, 28 Aug 2025, Jonathan Wakely wrote:

> On Thu, 28 Aug 2025 at 14:26, Tomasz Kamiński <[email protected]> wrote:
> >
> > This slightly improve the readability of error message, by suggesting
> > that 0 (literal) is expected as argument:
> >   invalid conversion from 'int' to 'std::__cmp_cat::__zero_literal*'
> >
> > libstdc++-v3/ChangeLog:
> >
> >         * libsupc++/compare (__cmp_cat::__zero_literal): Rename
> >         from __unspec.
> >         (__cmp_cat::__unspec): Rename to __zero_literal.
> >         (operator==, operator<, operator>, operator<=, operator>=):
> >         Replace __cmp_cat::__unspec to __cmp_cat::__zero_literal.
> >         * testsuite/18_support/comparisons/categories/zero_neg.cc:
> >         New test for type that is convertilbe to any pointer.
> > ---
> > The improvement from the name is slight, and very subjective, so would
> > be interested in other people opinion.
> 
> I think __literal_zero reads a little better for me than __zero_literal.

+1

> 
> 
> > Would like to preserve test, as I wondered about the case, and double
> > user-defined conversion didn't come to my mind imediatelly. This also
> > reason that we want to specify parameter as some type constructible from
> > pointer/nullptr_t instead of nullptr_t direclty.
> >
> > Testing on x86_64-linux locally.
> > OK for trunk for test?
> 
> Yes, the test is OK for trunk now.
> 
> > OK for trunk for rename?
> >
> >  libstdc++-v3/libsupc++/compare                | 70 +++++++++----------
> >  .../comparisons/categories/zero_neg.cc        | 16 +++++
> >  2 files changed, 51 insertions(+), 35 deletions(-)
> >
> > diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare
> > index ca7c9095c3c..e956275042b 100644
> > --- a/libstdc++-v3/libsupc++/compare
> > +++ b/libstdc++-v3/libsupc++/compare
> > @@ -73,9 +73,9 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >        __make(_Ord __o) noexcept
> >        { return _Ordering(__o); }
> >
> > -    struct __unspec
> > +    struct __zero_literal
> >      {
> > -      consteval __unspec(__unspec*) noexcept { }
> > +      consteval __zero_literal(__zero_literal*) noexcept { }
> >      };
> >    }
> >
> > @@ -112,7 +112,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >      // comparisons
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator==(partial_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator==(partial_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value == 0; }
> >
> >      [[nodiscard]]
> > @@ -121,52 +121,52 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator< (partial_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator< (partial_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value == -1; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator> (partial_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator> (partial_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value == 1; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator<=(partial_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator<=(partial_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_reverse() >= 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator>=(partial_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator>=(partial_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value >= 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator< (__cmp_cat::__unspec, partial_ordering __v) noexcept
> > +    operator< (__cmp_cat::__zero_literal, partial_ordering __v) noexcept
> >      { return __v._M_value == 1; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator> (__cmp_cat::__unspec, partial_ordering __v) noexcept
> > +    operator> (__cmp_cat::__zero_literal, partial_ordering __v) noexcept
> >      { return __v._M_value == -1; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator<=(__cmp_cat::__unspec, partial_ordering __v) noexcept
> > +    operator<=(__cmp_cat::__zero_literal, partial_ordering __v) noexcept
> >      { return 0 <= __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator>=(__cmp_cat::__unspec, partial_ordering __v) noexcept
> > +    operator>=(__cmp_cat::__zero_literal, partial_ordering __v) noexcept
> >      { return 0 <= __v._M_reverse(); }
> >
> >      [[nodiscard]]
> >      friend constexpr partial_ordering
> > -    operator<=>(partial_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator<=>(partial_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v; }
> >
> >      [[nodiscard]]
> >      friend constexpr partial_ordering
> > -    operator<=>(__cmp_cat::__unspec, partial_ordering __v) noexcept
> > +    operator<=>(__cmp_cat::__zero_literal, partial_ordering __v) noexcept
> >      { return partial_ordering(__cmp_cat::_Ord(__v._M_reverse())); }
> >    };
> >
> > @@ -209,7 +209,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >      // comparisons
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator==(weak_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator==(weak_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value == 0; }
> >
> >      [[nodiscard]]
> > @@ -218,52 +218,52 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator< (weak_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator< (weak_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value < 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator> (weak_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator> (weak_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value > 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator<=(weak_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator<=(weak_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value <= 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator>=(weak_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator>=(weak_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value >= 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator< (__cmp_cat::__unspec, weak_ordering __v) noexcept
> > +    operator< (__cmp_cat::__zero_literal, weak_ordering __v) noexcept
> >      { return 0 < __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator> (__cmp_cat::__unspec, weak_ordering __v) noexcept
> > +    operator> (__cmp_cat::__zero_literal, weak_ordering __v) noexcept
> >      { return 0 > __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator<=(__cmp_cat::__unspec, weak_ordering __v) noexcept
> > +    operator<=(__cmp_cat::__zero_literal, weak_ordering __v) noexcept
> >      { return 0 <= __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator>=(__cmp_cat::__unspec, weak_ordering __v) noexcept
> > +    operator>=(__cmp_cat::__zero_literal, weak_ordering __v) noexcept
> >      { return 0 >= __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr weak_ordering
> > -    operator<=>(weak_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator<=>(weak_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v; }
> >
> >      [[nodiscard]]
> >      friend constexpr weak_ordering
> > -    operator<=>(__cmp_cat::__unspec, weak_ordering __v) noexcept
> > +    operator<=>(__cmp_cat::__zero_literal, weak_ordering __v) noexcept
> >      { return weak_ordering(__cmp_cat::_Ord(-__v._M_value)); }
> >    };
> >
> > @@ -309,7 +309,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >      // comparisons
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator==(strong_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator==(strong_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value == 0; }
> >
> >      [[nodiscard]]
> > @@ -318,52 +318,52 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator< (strong_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator< (strong_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value < 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator> (strong_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator> (strong_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value > 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator<=(strong_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator<=(strong_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value <= 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator>=(strong_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator>=(strong_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v._M_value >= 0; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator< (__cmp_cat::__unspec, strong_ordering __v) noexcept
> > +    operator< (__cmp_cat::__zero_literal, strong_ordering __v) noexcept
> >      { return 0 < __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator> (__cmp_cat::__unspec, strong_ordering __v) noexcept
> > +    operator> (__cmp_cat::__zero_literal, strong_ordering __v) noexcept
> >      { return 0 > __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator<=(__cmp_cat::__unspec, strong_ordering __v) noexcept
> > +    operator<=(__cmp_cat::__zero_literal, strong_ordering __v) noexcept
> >      { return 0 <= __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr bool
> > -    operator>=(__cmp_cat::__unspec, strong_ordering __v) noexcept
> > +    operator>=(__cmp_cat::__zero_literal, strong_ordering __v) noexcept
> >      { return 0 >= __v._M_value; }
> >
> >      [[nodiscard]]
> >      friend constexpr strong_ordering
> > -    operator<=>(strong_ordering __v, __cmp_cat::__unspec) noexcept
> > +    operator<=>(strong_ordering __v, __cmp_cat::__zero_literal) noexcept
> >      { return __v; }
> >
> >      [[nodiscard]]
> >      friend constexpr strong_ordering
> > -    operator<=>(__cmp_cat::__unspec, strong_ordering __v) noexcept
> > +    operator<=>(__cmp_cat::__zero_literal, strong_ordering __v) noexcept
> >      { return strong_ordering(__cmp_cat::_Ord(-__v._M_value)); }
> >    };
> >
> > diff --git 
> > a/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc 
> > b/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc
> > index 2e6b9c14ddb..ce0ca8efa6f 100644
> > --- a/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc
> > +++ b/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc
> > @@ -23,6 +23,16 @@
> >  // C++20 [cmp.categories.pre]
> >  // "an argument other than a literal 0 is undefined"
> >
> > +struct PtrConv
> > +{
> > +  template<typename T>
> > +  consteval operator T*()
> > +  { return nullptr; }
> > +
> > +  consteval operator std::nullptr_t()
> > +  { return nullptr; }
> > +};
> > +
> >  void
> >  test01()
> >  {
> > @@ -48,6 +58,12 @@ test01()
> >    std::partial_ordering::equivalent == nullptr;
> >    std::weak_ordering::equivalent == nullptr;
> >    std::strong_ordering::equivalent == nullptr;
> > +
> > +  constexpr PtrConv c;
> > +  // requires two user-defined conversion
> > +  std::partial_ordering::equivalent == c; // { dg-error "no match for 
> > 'operator=='" }
> > +  std::weak_ordering::equivalent == c;    // { dg-error "no match for 
> > 'operator=='" }
> > +  std::strong_ordering::equivalent == c;  // { dg-error "no match for 
> > 'operator=='" }
> >  }
> >
> >  // { dg-prune-output "reinterpret_cast.* is not a constant expression" }
> > --
> > 2.50.1
> >
> 
> 

Reply via email to