]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/allocator_traits/members/destroy.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / members / destroy.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
45ba8f9f 2
83ffe9cd 3// Copyright (C) 2011-2023 Free Software Foundation, Inc.
45ba8f9f
JW
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#include <memory>
21#include <new>
22#include <testsuite_hooks.h>
23
24struct X
25{
26 static int counter;
27 ~X() { ++counter; }
28};
29
30int X::counter = 0;
31
32template<typename T>
33struct allocator_with_destroy
34{
35 typedef T value_type;
36
37 allocator_with_destroy() : called() { }
38
39 void destroy(T* p) { called = true; }
40
41 int called;
42};
43
44template<typename T>
45struct allocator_without_destroy
46{
47 typedef T value_type;
48
49 allocator_without_destroy() : called() { }
50
51 int called;
52};
53
54void test01()
55{
45ba8f9f
JW
56 typedef std::allocator_traits<allocator_with_destroy<X>> traits_type;
57 traits_type::allocator_type a;
58 X* p = 0;
59 traits_type::destroy(a, p);
60 VERIFY( a.called );
61 VERIFY( X::counter == 0 );
62}
63
64void test02()
65{
45ba8f9f
JW
66 typedef std::allocator_traits<allocator_without_destroy<X>> traits_type;
67 traits_type::allocator_type a;
68 char buf[sizeof(X)];
69 X* p = ::new (static_cast<void*>(buf)) X();
70 traits_type::destroy(a, p);
71 VERIFY( !a.called );
72 VERIFY( X::counter == 1 );
73}
74
75int main()
76{
77 test01();
78 test02();
79}