]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/dest/dest.cc
1 // Copyright (C) 2005-2021 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
21 #include <testsuite_hooks.h>
26 ~A() { ++dtor_count
; }
27 static long ctor_count
;
28 static long dtor_count
;
30 long A::ctor_count
= 0;
31 long A::dtor_count
= 0;
36 ~B() { ++dtor_count
; }
37 static long ctor_count
;
38 static long dtor_count
;
40 long B::ctor_count
= 0;
41 long B::dtor_count
= 0;
45 void operator()(const B
* p
) { delete p
; ++delete_count
; }
46 static long delete_count
;
48 long D::delete_count
= 0;
50 struct reset_count_struct
63 // 2.2.3.2 shared_ptr destructor [tr.util.smartptr.shared.dest]
69 reset_count_struct
__attribute__((unused
)) reset
;
72 std::tr1::shared_ptr
<A
> a
;
74 VERIFY( A::ctor_count
== 0 );
75 VERIFY( A::dtor_count
== 0 );
76 VERIFY( B::ctor_count
== 0 );
77 VERIFY( B::dtor_count
== 0 );
78 VERIFY( D::delete_count
== 0 );
87 reset_count_struct
__attribute__((unused
)) reset
;
89 std::tr1::shared_ptr
<A
> a
;
91 a
= std::tr1::shared_ptr
<A
>(new B
, D());
93 VERIFY( A::ctor_count
== 1 );
94 VERIFY( A::dtor_count
== 0 );
95 VERIFY( B::ctor_count
== 1 );
96 VERIFY( B::dtor_count
== 0 );
97 VERIFY( D::delete_count
== 0 );
102 // exclusive ownership
106 reset_count_struct
__attribute__((unused
)) reset
;
109 std::tr1::shared_ptr
<A
> a1(new B
);
110 std::tr1::shared_ptr
<A
> a2(new B
, D());
112 VERIFY( A::ctor_count
== 2 );
113 VERIFY( A::dtor_count
== 2 );
114 VERIFY( B::ctor_count
== 2 );
115 VERIFY( B::dtor_count
== 2 );
116 VERIFY( D::delete_count
== 1 );