[libcxx-commits] [libcxx] 20506fb - [libcxx] removes operator!= and globally guards against no spaceship operator

Christopher Di Bella via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 10 23:41:39 PDT 2021


Author: Christopher Di Bella
Date: 2021-05-11T06:40:54Z
New Revision: 20506fb1f361e41012506c6c252fd690541fc708

URL: https://github.com/llvm/llvm-project/commit/20506fb1f361e41012506c6c252fd690541fc708
DIFF: https://github.com/llvm/llvm-project/commit/20506fb1f361e41012506c6c252fd690541fc708.diff

LOG: [libcxx] removes operator!= and globally guards against no spaceship operator

* `operator!=` isn't in the spec
* `<compare>` is designed to work with `operator<=>` so it doesn't
  really make sense to have `operator<=>`-less friendly sections.

Depends on D100283.

Differential Revision: https://reviews.llvm.org/D100342

Added: 
    

Modified: 
    libcxx/include/compare
    libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
    libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
    libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
    libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/compare b/libcxx/include/compare
index ff3469d7f1b85..0a2b3d05a1ab4 100644
--- a/libcxx/include/compare
+++ b/libcxx/include/compare
@@ -129,8 +129,7 @@ namespace std {
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 17
-
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
 // exposition only
 enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char {
   __zero = 0,
@@ -184,24 +183,19 @@ public:
 
   // comparisons
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
 
-#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
 
   _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
-#endif
 
 private:
   _ValueT __value_;
@@ -233,10 +227,6 @@ constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__is_ordered() && __v.__value_ >= 0;
 }
 
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
-  return __v.__is_ordered() && 0 == __v.__value_;
-}
 _LIBCPP_INLINE_VISIBILITY
 constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
   return __v.__is_ordered() && 0 < __v.__value_;
@@ -254,16 +244,6 @@ constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
   return __v.__is_ordered() && 0 >= __v.__value_;
 }
 
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
-  return !__v.__is_ordered() || __v.__value_ != 0;
-}
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
-  return !__v.__is_ordered() || __v.__value_ != 0;
-}
-
-#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
 _LIBCPP_INLINE_VISIBILITY
 constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v;
@@ -272,7 +252,6 @@ _LIBCPP_INLINE_VISIBILITY
 constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
   return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
 }
-#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
 
 class weak_ordering {
   using _ValueT = signed char;
@@ -295,24 +274,19 @@ public:
 
   // comparisons
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
 
-#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
 
   _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
-#endif
 
 private:
   _ValueT __value_;
@@ -327,10 +301,6 @@ constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__value_ == 0;
 }
 _LIBCPP_INLINE_VISIBILITY
-constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-  return __v.__value_ != 0;
-}
-_LIBCPP_INLINE_VISIBILITY
 constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__value_ < 0;
 }
@@ -347,14 +317,6 @@ constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__value_ >= 0;
 }
 _LIBCPP_INLINE_VISIBILITY
-constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-  return 0 == __v.__value_;
-}
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-  return 0 != __v.__value_;
-}
-_LIBCPP_INLINE_VISIBILITY
 constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
   return 0 < __v.__value_;
 }
@@ -371,7 +333,6 @@ constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
   return 0 >= __v.__value_;
 }
 
-#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
 _LIBCPP_INLINE_VISIBILITY
 constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v;
@@ -380,8 +341,6 @@ _LIBCPP_INLINE_VISIBILITY
 constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
   return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
 }
-#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
-
 class strong_ordering {
   using _ValueT = signed char;
 
@@ -411,24 +370,19 @@ public:
 
   // comparisons
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
 
-#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
 
   _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
-#endif
 
 private:
   _ValueT __value_;
@@ -444,10 +398,6 @@ constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__value_ == 0;
 }
 _LIBCPP_INLINE_VISIBILITY
-constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-  return __v.__value_ != 0;
-}
-_LIBCPP_INLINE_VISIBILITY
 constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__value_ < 0;
 }
@@ -464,14 +414,6 @@ constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v.__value_ >= 0;
 }
 _LIBCPP_INLINE_VISIBILITY
-constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-  return 0 == __v.__value_;
-}
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-  return 0 != __v.__value_;
-}
-_LIBCPP_INLINE_VISIBILITY
 constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
   return 0 < __v.__value_;
 }
@@ -488,7 +430,6 @@ constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
   return 0 >= __v.__value_;
 }
 
-#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
 _LIBCPP_INLINE_VISIBILITY
 constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
   return __v;
@@ -497,7 +438,6 @@ _LIBCPP_INLINE_VISIBILITY
 constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
   return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
 }
-#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
 
 // named comparison functions
 _LIBCPP_INLINE_VISIBILITY
@@ -582,7 +522,7 @@ template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, con
 template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
 template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
 
-#endif // _LIBCPP_STD_VER > 17
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
 
 _LIBCPP_END_NAMESPACE_STD
 

diff  --git a/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp b/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
index fc21c03a3ddf0..c0fe4cb9613a0 100644
--- a/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
 
 // <compare>
 

diff  --git a/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
index c47307396c831..0b5169f4ac4f7 100644
--- a/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
 
 // <compare>
 

diff  --git a/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
index 40ffb356f4804..e8b973344485f 100644
--- a/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
 
 // <compare>
 

diff  --git a/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
index b39513a053303..d7f19ce18f759 100644
--- a/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
 
 // <compare>
 


        


More information about the libcxx-commits mailing list