summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-11-19 01:31:56 +0000
committerEric Fiselier <eric@efcs.ca>2014-11-19 01:31:56 +0000
commita3857d336efb2f49ebddf35f33016015f73a3b46 (patch)
treed42710a34036ae7efe2ed622bbfab7adbc315e56 /libcxx/test
parent4add3b13f00e78ed11028440bda8cb1ce00b0939 (diff)
downloadbcm5719-llvm-a3857d336efb2f49ebddf35f33016015f73a3b46.tar.gz
bcm5719-llvm-a3857d336efb2f49ebddf35f33016015f73a3b46.zip
diff --git a/test/language.support/support.types/nullptr_t.pass.cpp b/test/language.support/support.types/nullptr_t.pass.cpp
index 6c15fef..4d7c8b0 100644 --- a/test/language.support/support.types/nullptr_t.pass.cpp +++ b/test/language.support/support.types/nullptr_t.pass.cpp @@ -18,42 +18,62 @@ struct A A(std::nullptr_t) {} }; +template <class T> +void test_conversions() +{ + { + T p = 0; + assert(p == nullptr); + } + { + T p = nullptr; + assert(p == nullptr); + assert(nullptr == p); + assert(!(p != nullptr)); + assert(!(nullptr != p)); + } +} + +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)); +} + + int main() { static_assert(sizeof(std::nullptr_t) == sizeof(void*), "sizeof(std::nullptr_t) == sizeof(void*)"); - A* p = 0; - assert(p == nullptr); - void (A::*pmf)() = 0; -#ifdef __clang__ - // GCC 4.2 can't handle this - assert(pmf == nullptr); -#endif - int A::*pmd = 0; - assert(pmd == nullptr); - A a1(nullptr); - A a2(0); - bool b = nullptr; - assert(!b); - assert(nullptr == nullptr); - assert(nullptr <= nullptr); - assert(nullptr >= nullptr); - assert(!(nullptr != nullptr)); - assert(!(nullptr < nullptr)); - assert(!(nullptr > nullptr)); - A* a = nullptr; - assert(a == nullptr); - assert(a <= nullptr); - assert(a >= nullptr); - assert(!(a != nullptr)); - assert(!(a < nullptr)); - assert(!(a > nullptr)); - assert(nullptr == a); - assert(nullptr <= a); - assert(nullptr >= a); - assert(!(nullptr != a)); - assert(!(nullptr < a)); - assert(!(nullptr > a)); - std::ptrdiff_t i = reinterpret_cast<std::ptrdiff_t>(nullptr); - assert(i == 0); + + { + test_conversions<std::nullptr_t>(); + test_conversions<void*>(); + test_conversions<A*>(); + test_conversions<void(*)()>(); + test_conversions<void(A::*)()>(); + test_conversions<int A::*>(); + } + { + test_comparisons<std::nullptr_t>(); + test_comparisons<void*>(); + test_comparisons<A*>(); + test_comparisons<void(*)()>(); + } + { + bool b = nullptr; + assert(!b); + } } diff --git a/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp b/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp new file mode 100644 index 0000000..92bd879 --- /dev/null +++ b/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// typedef decltype(nullptr) nullptr_t; + +#include <cstddef> + +int main() +{ + std::ptrdiff_t i = static_cast<std::ptrdiff_t>(nullptr); +} diff --git a/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp b/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp new file mode 100644 index 0000000..34c7a93 --- /dev/null +++ b/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// NOTE: nullptr_t emulation cannot handle a reinterpret_cast to an +// integral type +// XFAIL: c++98, c++03 + +// typedef decltype(nullptr) nullptr_t; + + +#include <cstddef> +#include <cassert> + +int main() +{ + std::ptrdiff_t i = reinterpret_cast<std::ptrdiff_t>(nullptr); + assert(i == 0); +} llvm-svn: 222296
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/language.support/support.types/nullptr_t.pass.cpp88
-rw-r--r--libcxx/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp17
-rw-r--r--libcxx/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp24
3 files changed, 95 insertions, 34 deletions
diff --git a/libcxx/test/language.support/support.types/nullptr_t.pass.cpp b/libcxx/test/language.support/support.types/nullptr_t.pass.cpp
index 6c15fefdc48..4d7c8b0bc0a 100644
--- a/libcxx/test/language.support/support.types/nullptr_t.pass.cpp
+++ b/libcxx/test/language.support/support.types/nullptr_t.pass.cpp
@@ -18,42 +18,62 @@ struct A
A(std::nullptr_t) {}
};
+template <class T>
+void test_conversions()
+{
+ {
+ T p = 0;
+ assert(p == nullptr);
+ }
+ {
+ T p = nullptr;
+ assert(p == nullptr);
+ assert(nullptr == p);
+ assert(!(p != nullptr));
+ assert(!(nullptr != p));
+ }
+}
+
+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));
+}
+
+
int main()
{
static_assert(sizeof(std::nullptr_t) == sizeof(void*),
"sizeof(std::nullptr_t) == sizeof(void*)");
- A* p = 0;
- assert(p == nullptr);
- void (A::*pmf)() = 0;
-#ifdef __clang__
- // GCC 4.2 can't handle this
- assert(pmf == nullptr);
-#endif
- int A::*pmd = 0;
- assert(pmd == nullptr);
- A a1(nullptr);
- A a2(0);
- bool b = nullptr;
- assert(!b);
- assert(nullptr == nullptr);
- assert(nullptr <= nullptr);
- assert(nullptr >= nullptr);
- assert(!(nullptr != nullptr));
- assert(!(nullptr < nullptr));
- assert(!(nullptr > nullptr));
- A* a = nullptr;
- assert(a == nullptr);
- assert(a <= nullptr);
- assert(a >= nullptr);
- assert(!(a != nullptr));
- assert(!(a < nullptr));
- assert(!(a > nullptr));
- assert(nullptr == a);
- assert(nullptr <= a);
- assert(nullptr >= a);
- assert(!(nullptr != a));
- assert(!(nullptr < a));
- assert(!(nullptr > a));
- std::ptrdiff_t i = reinterpret_cast<std::ptrdiff_t>(nullptr);
- assert(i == 0);
+
+ {
+ test_conversions<std::nullptr_t>();
+ test_conversions<void*>();
+ test_conversions<A*>();
+ test_conversions<void(*)()>();
+ test_conversions<void(A::*)()>();
+ test_conversions<int A::*>();
+ }
+ {
+ test_comparisons<std::nullptr_t>();
+ test_comparisons<void*>();
+ test_comparisons<A*>();
+ test_comparisons<void(*)()>();
+ }
+ {
+ bool b = nullptr;
+ assert(!b);
+ }
}
diff --git a/libcxx/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp b/libcxx/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp
new file mode 100644
index 00000000000..92bd87943e1
--- /dev/null
+++ b/libcxx/test/language.support/support.types/nullptr_t_integral_cast.fail.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// typedef decltype(nullptr) nullptr_t;
+
+#include <cstddef>
+
+int main()
+{
+ std::ptrdiff_t i = static_cast<std::ptrdiff_t>(nullptr);
+}
diff --git a/libcxx/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp b/libcxx/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp
new file mode 100644
index 00000000000..34c7a93e41c
--- /dev/null
+++ b/libcxx/test/language.support/support.types/nullptr_t_integral_cast.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// NOTE: nullptr_t emulation cannot handle a reinterpret_cast to an
+// integral type
+// XFAIL: c++98, c++03
+
+// typedef decltype(nullptr) nullptr_t;
+
+
+#include <cstddef>
+#include <cassert>
+
+int main()
+{
+ std::ptrdiff_t i = reinterpret_cast<std::ptrdiff_t>(nullptr);
+ assert(i == 0);
+}
OpenPOWER on IntegriCloud