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     A* ptr = new A;
33     std::shared_ptr<A> p(ptr);
34     assert(A::count == 1);
35     assert(p.use_count() == 1);
36     assert(p.get() == ptr);
37     }
38     assert(A::count == 0);
39     {
40     A* ptr = new A;
41     std::shared_ptr<void> p(ptr);
42     assert(A::count == 1);
43     assert(p.use_count() == 1);
44     assert(p.get() == ptr);
45     }
46     assert(A::count == 0);
47 
48 #if TEST_STD_VER > 14
49     {
50       std::shared_ptr<A[8]> pA(new A[8]);
51       assert(pA.use_count() == 1);
52       assert(A::count == 8);
53     }
54     assert(A::count == 0);
55 
56     {
57       std::shared_ptr<A[]> pA(new A[8]);
58       assert(pA.use_count() == 1);
59       assert(A::count == 8);
60     }
61     assert(A::count == 0);
62 
63     {
64       std::shared_ptr<const A[]> pA(new A[8]);
65       assert(pA.use_count() == 1);
66       assert(A::count == 8);
67     }
68     assert(A::count == 0);
69 #endif
70 
71     return 0;
72 }
73