1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include <type_traits>
14 #include "test_macros.h"
16 // typedef decltype(nullptr) nullptr_t;
24 void test_conversions()
34 assert(!(p != nullptr));
35 assert(!(nullptr != p));
39 template <class T> struct Voider { typedef void type; };
40 template <class T, class = void> struct has_less : std::false_type {};
42 template <class T> struct has_less<T,
43 typename Voider<decltype(std::declval<T>() < nullptr)>::type> : std::true_type {};
46 void test_comparisons()
50 assert(!(p != nullptr));
52 assert(!(nullptr != p));
55 #if defined(__clang__)
56 #pragma clang diagnostic push
57 #pragma clang diagnostic ignored "-Wnull-conversion"
59 void test_nullptr_conversions() {
60 // GCC does not accept this due to CWG Defect #1423
61 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1423
62 #if defined(__clang__)
73 #if defined(__clang__)
74 #pragma clang diagnostic pop
80 static_assert(sizeof(std::nullptr_t) == sizeof(void*),
81 "sizeof(std::nullptr_t) == sizeof(void*)");
84 test_conversions<std::nullptr_t>();
85 test_conversions<void*>();
86 test_conversions<A*>();
87 test_conversions<void(*)()>();
88 test_conversions<void(A::*)()>();
89 test_conversions<int A::*>();
92 #ifdef _LIBCPP_HAS_NO_NULLPTR
93 static_assert(!has_less<std::nullptr_t>::value, "");
94 // FIXME: our c++03 nullptr emulation still allows for comparisons
95 // with other pointer types by way of the conversion operator.
96 //static_assert(!has_less<void*>::value, "");
98 // TODO Enable this assertion when all compilers implement core DR 583.
99 // static_assert(!has_less<std::nullptr_t>::value, "");
101 test_comparisons<std::nullptr_t>();
102 test_comparisons<void*>();
103 test_comparisons<A*>();
104 test_comparisons<void(*)()>();
106 test_nullptr_conversions();