]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/locale/cons/12352.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / 12352.cc
CommitLineData
f63a8495 1// { dg-require-namedlocale "" }
4216708a 2// { dg-require-namedlocale "en_US.ISO8859-1" }
f63a8495 3
7adcbafe 4// Copyright (C) 2003-2022 Free Software Foundation, Inc.
91675f9d
PC
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
91675f9d
PC
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
91675f9d
PC
20
21// 22.1.1.2 locale constructors and destructors [lib.locale.cons]
22
23#include <new>
24#include <locale>
25#include <cstdlib>
26#include <cstring>
38455b2b 27#include <testsuite_hooks.h>
91675f9d
PC
28
29int times_to_fail = 0;
30
31void* allocate(std::size_t n)
32{
33 if (!times_to_fail--)
34 return 0;
35
36 void* ret = std::malloc(n ? n : 1);
37 if (ret)
38 std::memset(ret, 0xbc, n);
39 return ret;
40}
41
42void deallocate(void* p)
43{
44 if (p)
45 std::free(p);
46}
47
1f153a1d 48void* operator new(std::size_t n) THROW (std::bad_alloc)
91675f9d
PC
49{
50 void* ret = allocate(n);
51 if (!ret)
52 throw std::bad_alloc();
53 return ret;
54}
55
1f153a1d 56void* operator new[](std::size_t n) THROW (std::bad_alloc)
91675f9d
PC
57{
58 void* ret = allocate(n);
59 if (!ret)
60 throw std::bad_alloc();
61 return ret;
62}
63
64void operator delete(void* p) throw()
65{
66 deallocate(p);
67}
68
69void operator delete[](void* p) throw()
70{
71 deallocate(p);
72}
73
13feb023
JW
74#if __cpp_sized_deallocation
75void operator delete(void* p, std::size_t) throw()
76{
77 deallocate(p);
78}
79
80void operator delete[](void* p, std::size_t) throw()
81{
82 deallocate(p);
83}
84#endif
85
91675f9d
PC
86void* operator new(std::size_t n, const std::nothrow_t&) throw()
87{
88 return allocate(n);
89}
90
91void* operator new[](std::size_t n, const std::nothrow_t&) throw()
92{
93 return allocate(n);
94}
95
96void operator delete(void* p, const std::nothrow_t&) throw()
97{
98 deallocate(p);
99}
100
101void operator delete[](void* p, const std::nothrow_t&) throw()
102{
103 deallocate(p);
104}
105
106// libstdc++/12352
107void test01(int iters)
108{
91675f9d
PC
109 for (int j = 0; j < iters; ++j)
110 {
111 for (int i = 0; i < 100; ++i)
112 {
113 times_to_fail = i;
114 try
115 {
f63a8495 116 std::locale loc1 = std::locale("");
2ea247d3
PC
117 std::locale loc2(loc1, std::locale::classic(),
118 std::locale::numeric);
4216708a 119 std::locale loc3 = std::locale(ISO_8859(1,en_US));
f09805bb
AS
120 std::locale loc4(loc3, std::locale::classic(),
121 std::locale::numeric);
91675f9d 122 }
2ea247d3 123 catch (std::exception&)
91675f9d
PC
124 {
125 }
126 }
127 }
128}
129
130int main(int argc, char* argv[])
131{
132 int iters = 1;
133 if (argc > 1)
134 iters = std::atoi(argv[1]);
135 if (iters < 1)
136 iters = 1;
137 test01(iters);
138
139 return 0;
140}