1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03 11 12 // <memory> 13 14 // shared_ptr 15 16 // shared_ptr(shared_ptr&& r); 17 18 #include <memory> 19 #include <cassert> 20 21 #include "test_macros.h" 22 23 struct A 24 { 25 static int count; 26 27 A() {++count;} 28 A(const A&) {++count;} 29 ~A() {--count;} 30 }; 31 32 int A::count = 0; 33 34 int main() 35 { 36 { 37 std::shared_ptr<A> pA(new A); 38 assert(pA.use_count() == 1); 39 assert(A::count == 1); 40 { 41 A* p = pA.get(); 42 std::shared_ptr<A> pA2(std::move(pA)); 43 assert(A::count == 1); 44 #if TEST_STD_VER >= 11 45 assert(pA.use_count() == 0); 46 assert(pA2.use_count() == 1); 47 #else 48 assert(pA.use_count() == 2); 49 assert(pA2.use_count() == 2); 50 #endif 51 assert(pA2.get() == p); 52 } 53 #if TEST_STD_VER >= 11 54 assert(pA.use_count() == 0); 55 assert(A::count == 0); 56 #else 57 assert(pA.use_count() == 1); 58 assert(A::count == 1); 59 #endif 60 } 61 assert(A::count == 0); 62 { 63 std::shared_ptr<A> pA; 64 assert(pA.use_count() == 0); 65 assert(A::count == 0); 66 { 67 std::shared_ptr<A> pA2(std::move(pA)); 68 assert(A::count == 0); 69 assert(pA.use_count() == 0); 70 assert(pA2.use_count() == 0); 71 assert(pA2.get() == pA.get()); 72 } 73 assert(pA.use_count() == 0); 74 assert(A::count == 0); 75 } 76 assert(A::count == 0); 77 } 78