66 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// shared_ptr12 13// void reset();14 15#include <memory>16#include <cassert>17 18#include "test_macros.h"19 20struct B21{22 static int count;23 24 B() {++count;}25 B(const B&) {++count;}26 virtual ~B() {--count;}27};28 29int B::count = 0;30 31struct A32 : public B33{34 static int count;35 36 A() {++count;}37 A(const A& other) : B(other) {++count;}38 ~A() {--count;}39};40 41int A::count = 0;42 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