diff options
Diffstat (limited to 'libcxx/test')
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); } |

