• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <memory>
11 
12 // shared_ptr
13 
14 // void reset();
15 
16 #include <memory>
17 #include <cassert>
18 
19 struct B
20 {
21     static int count;
22 
BB23     B() {++count;}
BB24     B(const B&) {++count;}
~BB25     virtual ~B() {--count;}
26 };
27 
28 int B::count = 0;
29 
30 struct A
31     : public B
32 {
33     static int count;
34 
AA35     A() {++count;}
AA36     A(const A&) {++count;}
~AA37     ~A() {--count;}
38 };
39 
40 int A::count = 0;
41 
main()42 int main()
43 {
44     {
45         std::shared_ptr<B> p(new B);
46         p.reset();
47         assert(A::count == 0);
48         assert(B::count == 0);
49         assert(p.use_count() == 0);
50         assert(p.get() == 0);
51     }
52     assert(A::count == 0);
53     {
54         std::shared_ptr<B> p;
55         p.reset();
56         assert(A::count == 0);
57         assert(B::count == 0);
58         assert(p.use_count() == 0);
59         assert(p.get() == 0);
60     }
61     assert(A::count == 0);
62 }
63