[libcxx-commits] [PATCH] D146372: [libc++]Don't warn when using operator<=> with 0

Igor Zhukov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 18 20:52:57 PDT 2023


fsb4000 updated this revision to Diff 506348.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146372/new/

https://reviews.llvm.org/D146372

Files:
  libcxx/include/__compare/ordering.h
  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


Index: libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
===================================================================
--- libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
+++ libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// ADDITIONAL_COMPILE_FLAGS: -Wzero-as-null-pointer-constant
 
 // <compare>
 
Index: libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
===================================================================
--- libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
+++ libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// ADDITIONAL_COMPILE_FLAGS: -Wzero-as-null-pointer-constant
 
 // <compare>
 
Index: libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
===================================================================
--- libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
+++ libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// ADDITIONAL_COMPILE_FLAGS: -Wzero-as-null-pointer-constant
 
 // <compare>
 
Index: libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
===================================================================
--- libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
+++ libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
@@ -23,9 +23,7 @@
   void(v op 0L);                                                               \
   void(0L op v);                                                               \
   void(v op nullptr);                                                          \
-  void(nullptr op v);                                                          \
-  void(v op(1 - 1));                                                           \
-  void((1 - 1) op v)
+  void(nullptr op v)
 
 #define TEST_PASS(v, op)                                                       \
   void(v op 0);                                                                \
Index: libcxx/include/__compare/ordering.h
===================================================================
--- libcxx/include/__compare/ordering.h
+++ libcxx/include/__compare/ordering.h
@@ -40,8 +40,12 @@
 inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
 
 struct _CmpUnspecifiedParam {
-  _LIBCPP_HIDE_FROM_ABI constexpr
-  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+  _LIBCPP_HIDE_FROM_ABI consteval
+  _CmpUnspecifiedParam(int __literal_zero) noexcept {
+    if (__literal_zero != 0) {
+      __builtin_abort();
+    }
+  }
 
   template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
   _CmpUnspecifiedParam(_Tp) = delete;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146372.506348.patch
Type: text/x-patch
Size: 3226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230319/d9173c65/attachment-0001.bin>


More information about the libcxx-commits mailing list