xref: /llvm-project/libcxx/test/std/depr/depr.auto.ptr/auto.ptr/AB.h (revision 851a335b1e64d0d32e15a8d2ace48c9b0967cd5a)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier #ifndef AB_H
105a83710eSEric Fiselier #define AB_H
115a83710eSEric Fiselier 
125a83710eSEric Fiselier #include <cassert>
135a83710eSEric Fiselier 
145a83710eSEric Fiselier class A
155a83710eSEric Fiselier {
165a83710eSEric Fiselier     int id_;
175a83710eSEric Fiselier public:
A(int id)185a83710eSEric Fiselier     explicit A(int id) : id_(id) {++count;}
A(const A & a)195a83710eSEric Fiselier     A(const A& a) : id_(a.id_) {++count;}
~A()205a83710eSEric Fiselier     virtual ~A() {assert(id_ >= 0); id_ = -1; --count;}
215a83710eSEric Fiselier 
22*851a335bSLouis Dionne     A& operator=(const A& other) { id_ = other.id_; return *this; }
23*851a335bSLouis Dionne 
245a83710eSEric Fiselier     static int count;
255a83710eSEric Fiselier };
265a83710eSEric Fiselier 
275a83710eSEric Fiselier int A::count = 0;
285a83710eSEric Fiselier 
295a83710eSEric Fiselier class B
305a83710eSEric Fiselier     : public A
315a83710eSEric Fiselier {
325a83710eSEric Fiselier public:
B(int id)335a83710eSEric Fiselier     explicit B(int id) : A(id) {++count;}
B(const B & a)345a83710eSEric Fiselier     B(const B& a) : A(a) {++count;}
~B()355a83710eSEric Fiselier     virtual ~B() {--count;}
365a83710eSEric Fiselier 
375a83710eSEric Fiselier     static int count;
385a83710eSEric Fiselier };
395a83710eSEric Fiselier 
405a83710eSEric Fiselier int B::count = 0;
415a83710eSEric Fiselier 
425a83710eSEric Fiselier #endif // AB_H
43