]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2011-2021 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>
27 struct hintable_allocator
30 struct const_void_pointer
{ };
31 typedef unsigned size_type
;
33 hintable_allocator() : called(false) { }
37 // this is the overload that should get called:
38 T
* allocate(size_type n
, const_void_pointer
) { called
= true; return 0; }
40 // none of these should get called:
41 T
* allocate(size_type n
);
42 T
* allocate(size_type n
, void*);
43 T
* allocate(size_type n
, const void*);
44 T
* allocate(size_type n
, const_void_pointer
) const;
49 typedef std::allocator_traits
<hintable_allocator
<X
>> traits_type
;
50 traits_type::allocator_type a
;
51 traits_type::const_void_pointer v
;
52 X
* p
__attribute__((unused
)) = traits_type::allocate(a
, 1, v
);
57 struct unhintable_allocator
60 typedef unsigned size_type
;
62 unhintable_allocator() : called(false) { }
66 // this is the overload that should get called:
67 T
* allocate(size_type n
) { called
= true; return 0; }
69 // this should not get called:
70 T
* allocate(size_type n
, void*);
75 typedef std::allocator_traits
<unhintable_allocator
<X
>> traits_type
;
76 traits_type::allocator_type a
;
77 traits_type::const_void_pointer v
;
78 X
* p
__attribute__((unused
)) = traits_type::allocate(a
, 1, v
);