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 #include "test_macros.h" 19 20 struct B 21 { 22 static int count; 23 BB24 B() {++count;} BB25 B(const B&) {++count;} ~BB26 virtual ~B() {--count;} 27 }; 28 29 int B::count = 0; 30 31 struct A 32 : public B 33 { 34 static int count; 35 AA36 A() {++count;} AA37 A(const A& other) : B(other) {++count;} ~AA38 ~A() {--count;} 39 }; 40 41 int A::count = 0; 42 main(int,char **)43int main(int, char**) 44 { 45 { 46 std::shared_ptr<B> p(new B); 47 p.reset(); 48 assert(A::count == 0); 49 assert(B::count == 0); 50 assert(p.use_count() == 0); 51 assert(p.get() == 0); 52 } 53 assert(A::count == 0); 54 { 55 std::shared_ptr<B> p; 56 p.reset(); 57 assert(A::count == 0); 58 assert(B::count == 0); 59 assert(p.use_count() == 0); 60 assert(p.get() == 0); 61 } 62 assert(A::count == 0); 63 64 return 0; 65 } 66