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 // <memory> 10 11 // template<class Y> explicit shared_ptr(Y* p); 12 13 #include <memory> 14 #include <cassert> 15 16 #include "test_macros.h" 17 18 struct A 19 { 20 static int count; 21 22 A() {++count;} 23 A(const A&) {++count;} 24 ~A() {--count;} 25 }; 26 27 int A::count = 0; 28 29 int main(int, char**) 30 { 31 { 32 assert(A::count == 0); 33 A* ptr = new A; 34 std::shared_ptr<A> p(ptr); 35 assert(A::count == 1); 36 assert(p.use_count() == 1); 37 assert(p.get() == ptr); 38 } 39 40 { 41 assert(A::count == 0); 42 A const* ptr = new A; 43 std::shared_ptr<A const> p(ptr); 44 assert(A::count == 1); 45 assert(p.use_count() == 1); 46 assert(p.get() == ptr); 47 } 48 49 { 50 assert(A::count == 0); 51 A* ptr = new A; 52 std::shared_ptr<void> p(ptr); 53 assert(A::count == 1); 54 assert(p.use_count() == 1); 55 assert(p.get() == ptr); 56 } 57 58 #if TEST_STD_VER > 14 59 { 60 assert(A::count == 0); 61 std::shared_ptr<A[8]> pA(new A[8]); 62 assert(pA.use_count() == 1); 63 assert(A::count == 8); 64 } 65 66 { 67 assert(A::count == 0); 68 std::shared_ptr<A[]> pA(new A[8]); 69 assert(pA.use_count() == 1); 70 assert(A::count == 8); 71 } 72 73 { 74 assert(A::count == 0); 75 std::shared_ptr<const A[]> pA(new A[8]); 76 assert(pA.use_count() == 1); 77 assert(A::count == 8); 78 } 79 #endif 80 81 return 0; 82 } 83