summaryrefslogtreecommitdiffstats
path: root/libcxx/test/utilities/memory/util.smartptr
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2014-03-05 03:12:04 +0000
committerMarshall Clow <mclow.lists@gmail.com>2014-03-05 03:12:04 +0000
commit4703f763766f173bf046c5504db5c299bde7cc0b (patch)
treec5853dae98c574366275d3e69da1675f0074217a /libcxx/test/utilities/memory/util.smartptr
parentacb842d5239afadd934ad2aef56b793d36436b19 (diff)
downloadbcm5719-llvm-4703f763766f173bf046c5504db5c299bde7cc0b.tar.gz
bcm5719-llvm-4703f763766f173bf046c5504db5c299bde7cc0b.zip
Update synposis in <memory> to show move semantics for weak_ptr; add tests for already existing move semantics. Mark LWG issues #2315 (no changes needed), 2316 (move semantics for weak_ptr), 2252 (previous commit) and 2271 (previous commit) as complete.
llvm-svn: 202931
Diffstat (limited to 'libcxx/test/utilities/memory/util.smartptr')
-rw-r--r--libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp16
-rw-r--r--libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp16
-rw-r--r--libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp17
-rw-r--r--libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp16
4 files changed, 65 insertions, 0 deletions
diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp
index 706d19ce3b9..e5713f37521 100644
--- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp
+++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp
@@ -59,4 +59,20 @@ int main()
}
assert(B::count == 0);
assert(A::count == 0);
+
+ {
+ const std::shared_ptr<A> ps(new A);
+ std::weak_ptr<A> pA(ps);
+ {
+ std::weak_ptr<A> pB;
+ pB = std::move(pA);
+ assert(B::count == 1);
+ assert(A::count == 1);
+ assert(pB.use_count() == 1);
+ }
+ assert(B::count == 1);
+ assert(A::count == 1);
+ }
+ assert(B::count == 0);
+ assert(A::count == 0);
}
diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp
index 76e701fe646..5a03d926f7d 100644
--- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp
+++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp
@@ -59,4 +59,20 @@ int main()
}
assert(B::count == 0);
assert(A::count == 0);
+
+ {
+ const std::shared_ptr<A> ps(new A);
+ std::weak_ptr<A> pA(ps);
+ {
+ std::weak_ptr<B> pB;
+ pB = std::move(pA);
+ assert(B::count == 1);
+ assert(A::count == 1);
+ assert(pB.use_count() == 1);
+ }
+ assert(B::count == 1);
+ assert(A::count == 1);
+ }
+ assert(B::count == 0);
+ assert(A::count == 0);
}
diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp
index f0e6c99d9e0..1fdf883a5c8 100644
--- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp
+++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp
@@ -12,6 +12,7 @@
// weak_ptr
// weak_ptr(const weak_ptr& r);
+// weak_ptr(weak_ptr &&r)
#include <memory>
#include <type_traits>
@@ -51,6 +52,12 @@ struct C
int C::count = 0;
+template <class T>
+std::weak_ptr<T> source (std::shared_ptr<T> p) { return std::weak_ptr<T>(p); }
+
+template <class T>
+void sink (std::weak_ptr<T> &&) {}
+
int main()
{
{
@@ -90,4 +97,14 @@ int main()
}
assert(B::count == 0);
assert(A::count == 0);
+
+ {
+ std::shared_ptr<A> ps(new A);
+ std::weak_ptr<A> pA = source(ps);
+ assert(pA.use_count() == 1);
+ assert(A::count == 1);
+ sink(std::move(pA)); // kill off the weak pointer
+ }
+ assert(B::count == 0);
+ assert(A::count == 0);
}
diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp
index 6af469188ca..70ad11b663d 100644
--- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp
+++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp
@@ -12,6 +12,7 @@
// weak_ptr
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
+// template<class Y> weak_ptr(weak_ptr<Y> &&r);
#include <memory>
#include <type_traits>
@@ -51,6 +52,12 @@ struct C
int C::count = 0;
+template <class T>
+std::weak_ptr<T> source (std::shared_ptr<T> p) { return std::weak_ptr<T>(p); }
+
+template <class T>
+void sink (std::weak_ptr<T> &&) {}
+
int main()
{
static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), "");
@@ -92,4 +99,13 @@ int main()
}
assert(B::count == 0);
assert(A::count == 0);
+
+ {
+ std::shared_ptr<A> ps(new A);
+ std::weak_ptr<A> pA = source(ps);
+ std::weak_ptr<B> pB(std::move(pA));
+ assert(pB.use_count() == 1);
+ }
+ assert(B::count == 0);
+ assert(A::count == 0);
}
OpenPOWER on IntegriCloud