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 19struct B 20{ 21 static int count; 22 23 B() {++count;} 24 B(const B&) {++count;} 25 virtual ~B() {--count;} 26}; 27 28int B::count = 0; 29 30struct A 31 : public B 32{ 33 static int count; 34 35 A() {++count;} 36 A(const A&) {++count;} 37 ~A() {--count;} 38}; 39 40int A::count = 0; 41 42int 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