[libcxx] r202931 - 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.

Marshall Clow mclow.lists at gmail.com
Tue Mar 4 19:12:05 PST 2014


Author: marshall
Date: Tue Mar  4 21:12:04 2014
New Revision: 202931

URL: http://llvm.org/viewvc/llvm-project?rev=202931&view=rev
Log:
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.

Modified:
    libcxx/trunk/include/memory
    libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp
    libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp
    libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp
    libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp
    libcxx/trunk/www/cxx1y_status.html

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=202931&r1=202930&r2=202931&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Tue Mar  4 21:12:04 2014
@@ -479,6 +479,8 @@ public:
     template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
     weak_ptr(weak_ptr const& r) noexcept;
     template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
+    weak_ptr(weak_ptr&& r) noexcept;                      // C++14
+    template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
 
     // destructor
     ~weak_ptr();
@@ -487,6 +489,8 @@ public:
     weak_ptr& operator=(weak_ptr const& r) noexcept;
     template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
     template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
+    weak_ptr& operator=(weak_ptr&& r) noexcept;                      // C++14
+    template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
 
     // modifiers
     void swap(weak_ptr& r) noexcept;

Modified: libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp?rev=202931&r1=202930&r2=202931&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp (original)
+++ libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp Tue Mar  4 21:12:04 2014
@@ -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);
 }

Modified: libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp?rev=202931&r1=202930&r2=202931&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp (original)
+++ libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp Tue Mar  4 21:12:04 2014
@@ -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);
 }

Modified: libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp?rev=202931&r1=202930&r2=202931&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp (original)
+++ libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp Tue Mar  4 21:12:04 2014
@@ -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);
 }

Modified: libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp?rev=202931&r1=202930&r2=202931&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp (original)
+++ libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp Tue Mar  4 21:12:04 2014
@@ -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);
 }

Modified: libcxx/trunk/www/cxx1y_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1y_status.html?rev=202931&r1=202930&r2=202931&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1y_status.html (original)
+++ libcxx/trunk/www/cxx1y_status.html Tue Mar  4 21:12:04 2014
@@ -217,10 +217,10 @@
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2291">2291</a></td><td>std::hash is vulnerable to collision DoS attack</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2142">2142</a></td><td>packaged_task::operator() synchronization too broad?</td><td>Issaquah</td><td></td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2240">2240</a></td><td>Probable misuse of term "function scope" in [thread.condition]</td><td>Issaquah</td><td>Complete</td></tr>
-	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2252">2252</a></td><td>Strong guarantee on vector::push_back() still broken with C++11?</td><td>Issaquah</td><td></td></tr>
+	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2252">2252</a></td><td>Strong guarantee on vector::push_back() still broken with C++11?</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2257">2257</a></td><td>Simplify container requirements with the new algorithms</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2268">2268</a></td><td>Setting a default argument in the declaration of a member function assign of std::basic_string</td><td>Issaquah</td><td>Complete</td></tr>
-	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2271">2271</a></td><td>regex_traits::lookup_classname specification unclear</td><td>Issaquah</td><td></td></tr>
+	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2271">2271</a></td><td>regex_traits::lookup_classname specification unclear</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2272">2272</a></td><td>quoted should use char_traits::eq for character comparison</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2278">2278</a></td><td>User-defined literals for Standard Library types</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2280">2280</a></td><td>begin / end for arrays should be constexpr and noexcept</td><td>Issaquah</td><td>Complete</td></tr>
@@ -247,8 +247,8 @@
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2308">2308</a></td><td>Clarify container destructor requirements w.r.t. std::array</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2313">2313</a></td><td>tuple_size should always derive from integral_constant<size_t, N></td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2314">2314</a></td><td>apply() should return decltype(auto) and use decay_t before tuple_size</td><td>Issaquah</td><td></td></tr>
-	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2315">2315</a></td><td>weak_ptr should be movable</td><td>Issaquah</td><td></td></tr>
-	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2316">2316</a></td><td>weak_ptr::lock() should be atomic</td><td>Issaquah</td><td></td></tr>
+	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2315">2315</a></td><td>weak_ptr should be movable</td><td>Issaquah</td><td>Complete</td></tr>
+	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2316">2316</a></td><td>weak_ptr::lock() should be atomic</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2317">2317</a></td><td>The type property queries should be UnaryTypeTraits returning size_t</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2320">2320</a></td><td>select_on_container_copy_construction() takes allocators, not containers</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2322">2322</a></td><td>Associative(initializer_list, stuff) constructors are underspecified</td><td>Issaquah</td><td>Complete</td></tr>





More information about the cfe-commits mailing list