]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/construct.cc
6d616f1eee88d516674159acf981607befcaf0dc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
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)
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.
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/>.
22 #include <testsuite_hooks.h>
28 X(const X
&) { ++counter
; }
29 explicit X(int) { ++counter
; }
30 X(int, int) { ++counter
; }
31 X(int, int, int) { ++counter
; }
41 fake_allocator() : counter() {}
45 T
* allocate(std::size_t n
) { return (T
*)new char[n
*sizeof(T
)]; }
46 void deallocate(T
* p
, std::size_t) { delete[] (char*)p
; }
48 // don't actually construct anything when these are called
49 void construct(T
* p
) { ++counter
; }
50 void construct(T
* p
, int, int) { ++counter
; }
55 bool test
__attribute__((unused
)) = true;
57 typedef std::allocator_traits
<fake_allocator
<X
>> traits_type
;
58 traits_type::allocator_type a
;
59 X
* p
= traits_type::allocate(a
, 1);
60 traits_type::construct(a
, p
);
61 VERIFY( a
.counter
== 1 );
62 traits_type::construct(a
, p
, 1);
63 VERIFY( a
.counter
== 1 );
64 VERIFY( X::counter
== 1 );
65 traits_type::destroy(a
, p
);
66 traits_type::construct(a
, p
, 1, 1);
67 VERIFY( a
.counter
== 2 );
68 VERIFY( X::counter
== 1 );
69 traits_type::construct(a
, p
, 1, 1, 1);
70 VERIFY( a
.counter
== 2 );
71 VERIFY( X::counter
== 2 );
72 traits_type::destroy(a
, p
);
73 traits_type::deallocate(a
, p
, 1);