Fix nullptr tests
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285117 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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 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 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);}
|
inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
// typedef decltype(nullptr) nullptr_t;
|
// typedef decltype(nullptr) nullptr_t;
|
||||||
|
|
||||||
struct A
|
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>
|
template <class T>
|
||||||
void test_comparisons()
|
void test_comparisons()
|
||||||
{
|
{
|
||||||
T p = nullptr;
|
T p = nullptr;
|
||||||
assert(p == nullptr);
|
assert(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));
|
||||||
assert(!(nullptr < p));
|
|
||||||
assert(!(nullptr > p));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
@@ -89,6 +89,15 @@ int main()
|
|||||||
test_conversions<int A::*>();
|
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<std::nullptr_t>();
|
||||||
test_comparisons<void*>();
|
test_comparisons<void*>();
|
||||||
test_comparisons<A*>();
|
test_comparisons<A*>();
|
||||||
|
|||||||
Reference in New Issue
Block a user