]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/allocator/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator / 1.cc
CommitLineData
3768cee7
BK
1// 2001-06-14 Benjamin Kosnik <bkoz@redhat.com>
2
7adcbafe 3// Copyright (C) 2001-2022 Free Software Foundation, Inc.
3768cee7
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
3768cee7
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
3768cee7 19
39de0e54
JW
20// { dg-require-effective-target std_allocator_new }
21
3768cee7
BK
22// 20.4.1.1 allocator members
23
24#include <memory>
af5fb6ab 25#include <stdexcept>
3768cee7 26#include <cstdlib>
fe413112 27#include <testsuite_hooks.h>
3768cee7 28
39f901e9
JW
29#if __cplusplus >= 201103L
30# define NOTHROW noexcept
31#else
32# define NOTHROW throw()
33#endif
34
3768cee7
BK
35struct gnu { };
36
37bool check_new = false;
38bool check_delete = false;
39
39de0e54 40void*
1f153a1d 41operator new(std::size_t n) THROW(std::bad_alloc)
3768cee7
BK
42{
43 check_new = true;
44 return std::malloc(n);
45}
46
39f901e9 47void operator delete(void *v) NOTHROW
3768cee7
BK
48{
49 check_delete = true;
50 return std::free(v);
51}
52
39f901e9
JW
53#if __cpp_sized_deallocation
54void operator delete(void *v, std::size_t) NOTHROW
55{
56 ::operator delete(v);
57}
58#endif
59
af5fb6ab 60void test01()
3768cee7 61{
3768cee7
BK
62 std::allocator<gnu> obj;
63
3768cee7
BK
64 gnu* pobj = obj.allocate(256);
65 VERIFY( check_new );
66
67 obj.deallocate(pobj, 256);
68 VERIFY( check_delete );
af5fb6ab
BK
69}
70
af5fb6ab
BK
71int main()
72{
73 test01();
3768cee7
BK
74 return 0;
75}
f90e600a 76