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 // shared_ptr
12 
13 // void reset();
14 
15 #include <memory>
16 #include <cassert>
17 
18 struct B
19 {
20     static int count;
21 
22     B() {++count;}
23     B(const B&) {++count;}
24     virtual ~B() {--count;}
25 };
26 
27 int B::count = 0;
28 
29 struct A
30     : public B
31 {
32     static int count;
33 
34     A() {++count;}
35     A(const A&) {++count;}
36     ~A() {--count;}
37 };
38 
39 int A::count = 0;
40 
41 int main(int, char**)
42 {
43     {
44         std::shared_ptr<B> p(new B);
45         p.reset();
46         assert(A::count == 0);
47         assert(B::count == 0);
48         assert(p.use_count() == 0);
49         assert(p.get() == 0);
50     }
51     assert(A::count == 0);
52     {
53         std::shared_ptr<B> p;
54         p.reset();
55         assert(A::count == 0);
56         assert(B::count == 0);
57         assert(p.use_count() == 0);
58         assert(p.get() == 0);
59     }
60     assert(A::count == 0);
61 
62   return 0;
63 }
64