]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alloc_ctor.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / memory / shared_ptr / cons / alloc_ctor.cc
CommitLineData
52066eae 1// { dg-do run { target c++14 } }
930d5602 2
8d9254fc 3// Copyright (C) 2015-2020 Free Software Foundation, Inc.
930d5602
FY
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20// 8.2.1 Class template shared_ptr [memory.smartptr.shared]
21
22#include <experimental/memory>
23#include <testsuite_hooks.h>
24#include <testsuite_allocator.h>
25
26using __gnu_test::tracker_allocator_counter;
27using __gnu_test::tracker_allocator;
28
29struct A { };
30void deletefunc(A* p) { delete [] p; }
31struct D
32{
33 void operator()(A* p) { delete [] p; ++delete_count; }
34 static long delete_count;
35};
36long D::delete_count = 0;
37
38// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const]
39
40// Construction with allocator
41
42int
43test01()
44{
930d5602
FY
45 tracker_allocator_counter::reset();
46
47 std::experimental::shared_ptr<A[5]> p1(new A[5], deletefunc, tracker_allocator<A[5]>());
48 std::size_t const sz = tracker_allocator_counter::get_allocation_count();
49 VERIFY( sz > 0 );
50 {
51 std::experimental::shared_ptr<A[5]> p2(p1);
52 VERIFY( p2.use_count() == 2 );
53 VERIFY( tracker_allocator_counter::get_allocation_count() == sz );
54 VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 );
55 }
56 VERIFY( p1.use_count() == 1 );
57 VERIFY( tracker_allocator_counter::get_allocation_count() == sz);
58 VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 );
59 p1.reset();
60 VERIFY( p1.use_count() == 0 );
61 VERIFY( tracker_allocator_counter::get_allocation_count() == sz );
62 VERIFY( tracker_allocator_counter::get_deallocation_count() == sz );
63
64 return 0;
65}
66
67int
68main()
69{
70 test01();
71 return 0;
72}