1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03 10 11 // <memory> 12 13 // shared_ptr 14 15 // shared_ptr(shared_ptr&& r); 16 17 #include <memory> 18 #include <cassert> 19 20 #include "test_macros.h" 21 22 struct A 23 { 24 static int count; 25 AA26 A() {++count;} AA27 A(const A&) {++count;} ~AA28 ~A() {--count;} 29 }; 30 31 int A::count = 0; 32 main(int,char **)33int main(int, char**) 34 { 35 { 36 std::shared_ptr<A> pA(new A); 37 assert(pA.use_count() == 1); 38 assert(A::count == 1); 39 { 40 A* p = pA.get(); 41 std::shared_ptr<A> pA2(std::move(pA)); 42 assert(A::count == 1); 43 #if TEST_STD_VER >= 11 44 assert(pA.use_count() == 0); 45 assert(pA2.use_count() == 1); 46 #else 47 assert(pA.use_count() == 2); 48 assert(pA2.use_count() == 2); 49 #endif 50 assert(pA2.get() == p); 51 } 52 #if TEST_STD_VER >= 11 53 assert(pA.use_count() == 0); 54 assert(A::count == 0); 55 #else 56 assert(pA.use_count() == 1); 57 assert(A::count == 1); 58 #endif 59 } 60 assert(A::count == 0); 61 { 62 std::shared_ptr<A> pA; 63 assert(pA.use_count() == 0); 64 assert(A::count == 0); 65 { 66 std::shared_ptr<A> pA2(std::move(pA)); 67 assert(A::count == 0); 68 assert(pA.use_count() == 0); 69 assert(pA2.use_count() == 0); 70 assert(pA2.get() == pA.get()); 71 } 72 assert(pA.use_count() == 0); 73 assert(A::count == 0); 74 } 75 assert(A::count == 0); 76 77 return 0; 78 } 79