[libcxx] r285117 - Fix nullptr tests

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 25 13:45:17 PDT 2016


Author: ericwf
Date: Tue Oct 25 15:45:17 2016
New Revision: 285117

URL: http://llvm.org/viewvc/llvm-project?rev=285117&view=rev
Log:
Fix nullptr tests

Modified:
    libcxx/trunk/include/__nullptr
    libcxx/trunk/test/std/language.support/support.types/nullptr_t.pass.cpp

Modified: libcxx/trunk/include/__nullptr
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__nullptr?rev=285117&r1=285116&r2=285117&view=diff
==============================================================================
--- libcxx/trunk/include/__nullptr (original)
+++ libcxx/trunk/include/__nullptr Tue Oct 25 15:45:17 2016
@@ -42,10 +42,6 @@ struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
 
     friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
     friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
 };
 
 inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}

Modified: libcxx/trunk/test/std/language.support/support.types/nullptr_t.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.types/nullptr_t.pass.cpp?rev=285117&r1=285116&r2=285117&view=diff
==============================================================================
--- libcxx/trunk/test/std/language.support/support.types/nullptr_t.pass.cpp (original)
+++ libcxx/trunk/test/std/language.support/support.types/nullptr_t.pass.cpp Tue Oct 25 15:45:17 2016
@@ -11,6 +11,8 @@
 #include <type_traits>
 #include <cassert>
 
+#include "test_macros.h"
+
 // typedef decltype(nullptr) nullptr_t;
 
 struct A
@@ -34,22 +36,20 @@ void test_conversions()
     }
 }
 
+template <class T> struct Voider { typedef void type; };
+template <class T, class = void> struct has_less : std::false_type {};
+
+template <class T> struct has_less<T,
+    typename Voider<decltype(std::declval<T>() < nullptr)>::type> : std::true_type {};
+
 template <class T>
 void test_comparisons()
 {
     T p = nullptr;
     assert(p == nullptr);
-    assert(p <= nullptr);
-    assert(p >= nullptr);
     assert(!(p != nullptr));
-    assert(!(p < nullptr));
-    assert(!(p > nullptr));
     assert(nullptr == p);
-    assert(nullptr <= p);
-    assert(nullptr >= p);
     assert(!(nullptr != p));
-    assert(!(nullptr < p));
-    assert(!(nullptr > p));
 }
 
 #if defined(__clang__)
@@ -89,6 +89,15 @@ int main()
         test_conversions<int A::*>();
     }
     {
+#ifdef _LIBCPP_HAS_NO_NULLPTR
+        static_assert(!has_less<std::nullptr_t>::value, "");
+        // FIXME: our c++03 nullptr emulation still allows for comparisons
+        // with other pointer types by way of the conversion operator.
+        //static_assert(!has_less<void*>::value, "");
+#else
+        // TODO Enable this assertion when all compilers implement core DR 583.
+        // static_assert(!has_less<std::nullptr_t>::value, "");
+#endif
         test_comparisons<std::nullptr_t>();
         test_comparisons<void*>();
         test_comparisons<A*>();




More information about the cfe-commits mailing list