[libcxx-commits] [libcxx] 6b9e0af - [libc++] Add test coverage for std::shared_ptr<const T>

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 10 05:49:39 PST 2022


Author: Louis Dionne
Date: 2022-03-10T08:49:31-05:00
New Revision: 6b9e0af8db2a9e2344d52d2de46efd367725a856

URL: https://github.com/llvm/llvm-project/commit/6b9e0af8db2a9e2344d52d2de46efd367725a856
DIFF: https://github.com/llvm/llvm-project/commit/6b9e0af8db2a9e2344d52d2de46efd367725a856.diff

LOG: [libc++] Add test coverage for std::shared_ptr<const T>

Those tests were extracted from D120996.

Differential Revision: https://reviews.llvm.org/D121340

Added: 
    

Modified: 
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
index 117503c18abed..6f641cec24bf4 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
@@ -46,19 +46,34 @@ int A::count = 0;
 
 int main(int, char**)
 {
-  globalMemCounter.reset();
-  {
-    std::auto_ptr<A> ptr(new A);
-    A* raw_ptr = ptr.get();
-    std::shared_ptr<B> p(std::move(ptr));
-    assert(A::count == 1);
-    assert(B::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == raw_ptr);
-    assert(ptr.get() == 0);
-  }
+    globalMemCounter.reset();
+    {
+        std::auto_ptr<A> ptr(new A);
+        A* raw_ptr = ptr.get();
+        std::shared_ptr<B> p(std::move(ptr));
+        assert(A::count == 1);
+        assert(B::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == raw_ptr);
+        assert(ptr.get() == 0);
+    }
+    assert(A::count == 0);
+    assert(globalMemCounter.checkOutstandingNewEq(0));
+
+    globalMemCounter.reset();
+    {
+        std::auto_ptr<A const> ptr(new A);
+        A const* raw_ptr = ptr.get();
+        std::shared_ptr<B const> p(std::move(ptr));
+        assert(A::count == 1);
+        assert(B::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == raw_ptr);
+        assert(ptr.get() == 0);
+    }
     assert(A::count == 0);
     assert(globalMemCounter.checkOutstandingNewEq(0));
+
 #if !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT)
     {
         std::auto_ptr<A> ptr(new A);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
index 05810e80e914a..7373adf6eaa02 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
@@ -22,7 +22,7 @@
 struct A {};
 
 struct D {
-  void operator()(A* ptr) const
+  void operator()(A const* ptr) const
   {
     delete ptr;
   }
@@ -39,22 +39,49 @@ int main(int, char**)
     assert(s.use_count() == 2);
     assert(s0.get() == s.get());
   }
+  {
+    std::shared_ptr<A const> s0(new A);
+    std::weak_ptr<A const> w = s0;
+    auto s = std::shared_ptr(w);
+    ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A const>);
+    assert(s0.use_count() == 2);
+    assert(s.use_count() == 2);
+    assert(s0.get() == s.get());
+  }
+
   {
     std::unique_ptr<A> u(new A);
-    A* const uPointee = u.get();
+    A* uPointee = u.get();
     std::shared_ptr s = std::move(u);
     ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A>);
     assert(u == nullptr);
     assert(s.get() == uPointee);
   }
+  {
+    std::unique_ptr<A const> u(new A);
+    A const* uPointee = u.get();
+    std::shared_ptr s = std::move(u);
+    ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A const>);
+    assert(u == nullptr);
+    assert(s.get() == uPointee);
+  }
+
   {
     std::unique_ptr<A, D> u(new A, D{});
-    A* const uPointee = u.get();
+    A* uPointee = u.get();
     std::shared_ptr s(std::move(u));
     ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A>);
     assert(u == nullptr);
     assert(s.get() == uPointee);
   }
+  {
+    std::unique_ptr<A const, D> u(new A, D{});
+    A const* uPointee = u.get();
+    std::shared_ptr s(std::move(u));
+    ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A const>);
+    assert(u == nullptr);
+    assert(s.get() == uPointee);
+  }
 
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
index 4efa18f63f523..6ac7ad6447619 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
@@ -26,8 +26,11 @@ void test() {
 
 int main(int, char**) {
   test<int>();
+  test<int const>();
   test<A>();
+  test<A const>();
   test<int*>();
+  test<int const*>();
   test<int[]>();
   test<int[8]>();
 

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
index c9a46dc48f531..f307c9e9f239d 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
@@ -17,9 +17,17 @@
 
 int main(int, char**)
 {
+  {
     std::shared_ptr<int> p(nullptr);
     assert(p.use_count() == 0);
     assert(p.get() == 0);
+  }
+
+  {
+    std::shared_ptr<int const> p(nullptr);
+    assert(p.use_count() == 0);
+    assert(p.get() == 0);
+  }
 
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
index b84e1659caadb..49497b6956b9f 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
@@ -31,21 +31,26 @@ int A::count = 0;
 int main(int, char**)
 {
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
 
-  return 0;
+    {
+        std::shared_ptr<A const> p(nullptr, test_deleter<A const>(3));
+        assert(p.get() == nullptr);
+    }
+
+    return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
index 4d59d7f5667f8..4e9fc227b99e8 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
@@ -32,19 +32,19 @@ int main(int, char**)
 {
     test_allocator_statistics alloc_stats;
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
-    assert(alloc_stats.count == 1);
-    assert(alloc_stats.alloc_count == 1);
+        assert(alloc_stats.count == 1);
+        assert(alloc_stats.alloc_count == 1);
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
@@ -52,37 +52,39 @@ int main(int, char**)
     assert(alloc_stats.count == 0);
     assert(alloc_stats.alloc_count == 0);
     test_deleter<A>::dealloc_count = 0;
+
     // Test an allocator with a minimal interface
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(1), bare_allocator<void>());
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count ==1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(1), bare_allocator<void>());
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count ==1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 1);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 1);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
     test_deleter<A>::dealloc_count = 0;
+
 #if TEST_STD_VER >= 11
     // Test an allocator that returns class-type pointers
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>());
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count ==1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>());
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count ==1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 1);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 1);
 #endif
     }
     assert(A::count == 0);
@@ -90,5 +92,11 @@ int main(int, char**)
     assert(test_deleter<A>::dealloc_count == 1);
 #endif
 
+    // Make sure we can use this constructor with a pointer-to-const
+    {
+        std::shared_ptr<A const> p(nullptr, test_deleter<A const>(3), test_allocator<A>(5, &alloc_stats));
+        (void)p;
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
index c88bdd1c6e561..ef3270efc8253 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
@@ -29,43 +29,53 @@ int A::count = 0;
 int main(int, char**)
 {
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr);
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
+        assert(A::count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr);
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
     }
-    assert(A::count == 0);
+
+    {
+        assert(A::count == 0);
+        A const* ptr = new A;
+        std::shared_ptr<A const> p(ptr);
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+    }
+
     {
-    A* ptr = new A;
-    std::shared_ptr<void> p(ptr);
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
+        assert(A::count == 0);
+        A* ptr = new A;
+        std::shared_ptr<void> p(ptr);
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
     }
-    assert(A::count == 0);
 
 #if TEST_STD_VER > 14
     {
-      std::shared_ptr<A[8]> pA(new A[8]);
-      assert(pA.use_count() == 1);
-      assert(A::count == 8);
+        assert(A::count == 0);
+        std::shared_ptr<A[8]> pA(new A[8]);
+        assert(pA.use_count() == 1);
+        assert(A::count == 8);
     }
-    assert(A::count == 0);
 
     {
-      std::shared_ptr<A[]> pA(new A[8]);
-      assert(pA.use_count() == 1);
-      assert(A::count == 8);
+        assert(A::count == 0);
+        std::shared_ptr<A[]> pA(new A[8]);
+        assert(pA.use_count() == 1);
+        assert(A::count == 8);
     }
-    assert(A::count == 0);
 
     {
-      std::shared_ptr<const A[]> pA(new A[8]);
-      assert(pA.use_count() == 1);
-      assert(A::count == 8);
+          assert(A::count == 0);
+        std::shared_ptr<const A[]> pA(new A[8]);
+        assert(pA.use_count() == 1);
+        assert(A::count == 8);
     }
-    assert(A::count == 0);
 #endif
 
     return 0;

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
index e5abbebb962bb..b3580e25fe52c 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
@@ -63,23 +63,29 @@ class MoveDeleter
 int main(int, char**)
 {
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3));
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr, test_deleter<A>(3));
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
 
+    {
+        A const* ptr = new A;
+        std::shared_ptr<A const> p(ptr, test_deleter<A const>(3));
+        assert(p.get() == ptr);
+    }
+
     {
         // Make sure we can't construct with:
         //    a) a deleter that doesn't have an operator ()(int*)

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
index 3b86b07d79234..2fc25282230c8 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
@@ -62,62 +62,92 @@ class MoveDeleter
 
 int main(int, char**)
 {
-    test_allocator_statistics alloc_stats;
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        test_allocator_statistics alloc_stats;
+        {
+            A* ptr = new A;
+            std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
+            assert(A::count == 1);
+            assert(p.use_count() == 1);
+            assert(p.get() == ptr);
+            assert(test_deleter<A>::count == 1);
+            assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+            test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+            assert(d);
+            assert(d->state() == 3);
 #endif
-    assert(alloc_stats.count == 1);
-    assert(alloc_stats.alloc_count == 1);
+            assert(alloc_stats.count == 1);
+            assert(alloc_stats.alloc_count == 1);
+        }
+        assert(A::count == 0);
+        assert(test_deleter<A>::count == 0);
+        assert(test_deleter<A>::dealloc_count == 1);
+        assert(alloc_stats.count == 0);
+        assert(alloc_stats.alloc_count == 0);
+        test_deleter<A>::dealloc_count = 0;
     }
-    assert(A::count == 0);
-    assert(test_deleter<A>::count == 0);
-    assert(test_deleter<A>::dealloc_count == 1);
-    assert(alloc_stats.count == 0);
-    assert(alloc_stats.alloc_count == 0);
-    test_deleter<A>::dealloc_count = 0;
+
+    {
+        test_allocator_statistics alloc_stats;
+        {
+            A const* ptr = new A;
+            std::shared_ptr<A const> p(ptr, test_deleter<A const>(3), test_allocator<A>(5, &alloc_stats));
+            assert(A::count == 1);
+            assert(p.use_count() == 1);
+            assert(p.get() == ptr);
+            assert(test_deleter<A const>::count == 1);
+            assert(test_deleter<A const>::dealloc_count == 0);
+#ifndef TEST_HAS_NO_RTTI
+            test_deleter<A const>* d = std::get_deleter<test_deleter<A const> >(p);
+            assert(d);
+            assert(d->state() == 3);
+#endif
+            assert(alloc_stats.count == 1);
+            assert(alloc_stats.alloc_count == 1);
+        }
+        assert(A::count == 0);
+        assert(test_deleter<A const>::count == 0);
+        assert(test_deleter<A const>::dealloc_count == 1);
+        assert(alloc_stats.count == 0);
+        assert(alloc_stats.alloc_count == 0);
+        test_deleter<A const>::dealloc_count = 0;
+    }
+
     // Test an allocator with a minimal interface
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3), bare_allocator<void>());
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr, test_deleter<A>(3), bare_allocator<void>());
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
     test_deleter<A>::dealloc_count = 0;
+
 #if TEST_STD_VER >= 11
     // Test an allocator that returns class-type pointers
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3), min_allocator<void>());
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr, test_deleter<A>(3), min_allocator<void>());
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
index c9bd0f0331158..fcb6ae71b4839 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
@@ -61,5 +61,11 @@ int main(int, char**)
     }
     assert(A::count == 0);
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        std::shared_ptr<A const> pA2(pA);
+        assert(pA.get() == pA2.get());
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
index 20cfd52d6901d..26f381c9a2892 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
@@ -152,5 +152,11 @@ int main(int, char**)
     assert(A::count == 0);
 #endif
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        std::shared_ptr<B const> pB(pA);
+        assert(pB.get() == pA.get());
+    }
+
     return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
index 167baf87825db..84ec26eb140ee 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
@@ -129,5 +129,12 @@ int main(int, char**)
     assert(A::count == 0);
 #endif
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        B const* p = pA.get();
+        std::shared_ptr<B const> pB(std::move(pA));
+        assert(pB.get() == p);
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
index 580ab3d35f1b3..9ef8ed7876f67 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
@@ -61,6 +61,26 @@ int main(int, char**)
     assert(A::count == 0);
     assert(B::count == 0);
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        assert(pA.use_count() == 1);
+
+        {
+            B const b;
+            std::shared_ptr<B const> pB(pA, &b);
+            assert(A::count == 1);
+            assert(B::count == 1);
+            assert(pA.use_count() == 2);
+            assert(pB.use_count() == 2);
+            assert(pB.get() == &b);
+        }
+        assert(pA.use_count() == 1);
+        assert(A::count == 1);
+        assert(B::count == 0);
+    }
+    assert(A::count == 0);
+    assert(B::count == 0);
+
     int *pi = new int;
     {
       std::shared_ptr<int> p1(nullptr);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
index bc000949c6857..8637e3fc8cf29 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
@@ -57,6 +57,7 @@ int main(int, char**)
         assert(A::count == 1);
 #endif
     }
+
     assert(A::count == 0);
     {
         std::shared_ptr<A> pA;
@@ -74,5 +75,12 @@ int main(int, char**)
     }
     assert(A::count == 0);
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        A const* p = pA.get();
+        std::shared_ptr<A const> pA2(std::move(pA));
+        assert(pA2.get() == p);
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
index ef0b9102c6cda..a86bff84435f9 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
@@ -94,6 +94,18 @@ int main(int, char**)
         assert(p.get() == raw_ptr);
         assert(ptr.get() == 0);
     }
+
+    {
+        std::unique_ptr<A const> ptr(new A);
+        A const* raw_ptr = ptr.get();
+        std::shared_ptr<B const> p(std::move(ptr));
+        assert(A::count == 1);
+        assert(B::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == raw_ptr);
+        assert(ptr.get() == 0);
+    }
+
 #ifndef TEST_HAS_NO_EXCEPTIONS
     assert(A::count == 0);
     {

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
index 30fa6ccd1806a..57d7cc58ef68c 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
@@ -65,6 +65,15 @@ int main(int, char**)
         assert(A::count == 1);
     }
     assert(A::count == 0);
+    {
+        std::shared_ptr<A const> sp0(new A);
+        std::weak_ptr<A const> wp(sp0);
+        std::shared_ptr<A const> sp(wp);
+        assert(sp.use_count() == 2);
+        assert(sp.get() == sp0.get());
+        assert(A::count == 1);
+    }
+    assert(A::count == 0);
 #ifndef TEST_HAS_NO_EXCEPTIONS
     {
         std::shared_ptr<A> sp0(new A);


        


More information about the libcxx-commits mailing list