1 // { dg-do run { target c++11 } }
2 // { dg-require-effective-target hosted }
4 // Copyright (C) 2010-2022 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 20.9.11.2 Class template shared_ptr [util.smartptr.shared]
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // 20.9.11.2.1 shared_ptr constructors [util.smartptr.shared.const]
30 // Construction from nullptr
35 deleter() : count(0) { }
36 void operator()(std::nullptr_t
) { ++count
; }
37 void operator()(int*) const { throw "wrong type passed to deleter"; }
43 std::shared_ptr
<int> p
= nullptr;
44 VERIFY( p
.get() == nullptr );
45 VERIFY( p
.use_count() == 0 );
53 std::shared_ptr
<int> p(nullptr, std::ref(d
));
54 VERIFY( p
.get() == nullptr );
55 VERIFY( p
.use_count() == 1 );
58 VERIFY( p
.use_count() == 0 );
59 VERIFY( d
.count
== 1 );
67 __gnu_test::tracker_allocator
<int> a
;
68 std::shared_ptr
<int> p(nullptr, std::ref(d
), a
);
69 VERIFY( p
.get() == nullptr );
70 VERIFY( p
.use_count() == 1 );
73 VERIFY( p
.use_count() == 0 );
74 VERIFY( d
.count
== 1 );
76 typedef __gnu_test::tracker_allocator_counter c
;
77 VERIFY( c::get_destruct_count() == c::get_construct_count() );
78 VERIFY( c::get_deallocation_count() == c::get_allocation_count() );