summaryrefslogtreecommitdiffstats
path: root/libcxx/test/utilities/memory
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2012-02-21 21:02:58 +0000
committerHoward Hinnant <hhinnant@apple.com>2012-02-21 21:02:58 +0000
commit67f396476609d1eeb10b565f22f02eaa2fc172ea (patch)
treee052da12f832c9e3a4be38b164c6af3881bd61ea /libcxx/test/utilities/memory
parent0460ae8d80ccefde07b00cbec7105e7a4ff16d6e (diff)
downloadbcm5719-llvm-67f396476609d1eeb10b565f22f02eaa2fc172ea.tar.gz
bcm5719-llvm-67f396476609d1eeb10b565f22f02eaa2fc172ea.zip
Modernize relational operators for shared_ptr and unique_ptr. This includes adding support for nullptr, and using less<T*>. Fixes http://llvm.org/bugs/show_bug.cgi?id=12056.
llvm-svn: 151084
Diffstat (limited to 'libcxx/test/utilities/memory')
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp71
-rw-r--r--libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp71
2 files changed, 142 insertions, 0 deletions
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp
new file mode 100644
index 00000000000..deb615ecb1d
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// shared_ptr
+
+// template <class T, class D>
+// bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
+// template <class T, class D>
+// bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
+// template <class T, class D>
+// bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
+// template <class T, class D>
+// bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
+// template <class T, class D>
+// bool operator<(const unique_ptr<T, D>& x, nullptr_t) noexcept;
+// template <class T, class D>
+// bool operator<(nullptr_t, const unique_ptr<T, D>& y) noexcept;
+// template <class T, class D>
+// bool operator<=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
+// template <class T, class D>
+// bool operator<=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
+// template <class T, class D>
+// bool operator>(const unique_ptr<T, D>& x, nullptr_t) noexcept;
+// template <class T, class D>
+// bool operator>(nullptr_t, const unique_ptr<T, D>& y) noexcept;
+// template <class T, class D>
+// bool operator>=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
+// template <class T, class D>
+// bool operator>=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
+
+#include <memory>
+#include <cassert>
+
+void do_nothing(int*) {}
+
+int main()
+{
+ int* ptr1(new int);
+ int* ptr2(new int);
+ const std::unique_ptr<int> p1(new int(1));
+ assert(!(p1 == nullptr));
+ assert(!(nullptr == p1));
+ assert(!(p1 < nullptr));
+ assert( (nullptr < p1));
+ assert(!(p1 <= nullptr));
+ assert( (nullptr <= p1));
+ assert( (p1 > nullptr));
+ assert(!(nullptr > p1));
+ assert( (p1 >= nullptr));
+ assert(!(nullptr >= p1));
+
+ const std::unique_ptr<int> p2;
+ assert( (p2 == nullptr));
+ assert( (nullptr == p2));
+ assert(!(p2 < nullptr));
+ assert(!(nullptr < p2));
+ assert( (p2 <= nullptr));
+ assert( (nullptr <= p2));
+ assert(!(p2 > nullptr));
+ assert(!(nullptr > p2));
+ assert( (p2 >= nullptr));
+ assert( (nullptr >= p2));
+}
diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp
new file mode 100644
index 00000000000..d8d3113fc30
--- /dev/null
+++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// shared_ptr
+
+// template <class T>
+// bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
+// template <class T>
+// bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
+// template <class T>
+// bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
+// template <class T>
+// bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
+// template <class T>
+// bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
+// template <class T>
+// bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
+// template <class T>
+// bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
+// template <class T>
+// bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
+// template <class T>
+// bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
+// template <class T>
+// bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
+// template <class T>
+// bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
+// template <class T>
+// bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
+
+#include <memory>
+#include <cassert>
+
+void do_nothing(int*) {}
+
+int main()
+{
+ int* ptr1(new int);
+ int* ptr2(new int);
+ const std::shared_ptr<int> p1(new int(1));
+ assert(!(p1 == nullptr));
+ assert(!(nullptr == p1));
+ assert(!(p1 < nullptr));
+ assert( (nullptr < p1));
+ assert(!(p1 <= nullptr));
+ assert( (nullptr <= p1));
+ assert( (p1 > nullptr));
+ assert(!(nullptr > p1));
+ assert( (p1 >= nullptr));
+ assert(!(nullptr >= p1));
+
+ const std::shared_ptr<int> p2;
+ assert( (p2 == nullptr));
+ assert( (nullptr == p2));
+ assert(!(p2 < nullptr));
+ assert(!(nullptr < p2));
+ assert( (p2 <= nullptr));
+ assert( (nullptr <= p2));
+ assert(!(p2 > nullptr));
+ assert(!(nullptr > p2));
+ assert( (p2 >= nullptr));
+ assert( (nullptr >= p2));
+}
OpenPOWER on IntegriCloud