2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / 12352.cc
blobb58f61bfa97e45043cca754641121dd4b7d915a4
1 // Copyright (C) 2003 Free Software Foundation
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
19 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
21 #include <new>
22 #include <locale>
23 #include <cstdlib>
24 #include <cstring>
25 #include <testsuite_hooks.h>
27 int times_to_fail = 0;
29 void* allocate(std::size_t n)
31 if (!times_to_fail--)
32 return 0;
34 void* ret = std::malloc(n ? n : 1);
35 if (ret)
36 std::memset(ret, 0xbc, n);
37 return ret;
40 void deallocate(void* p)
42 if (p)
43 std::free(p);
46 void* operator new(std::size_t n) throw (std::bad_alloc)
48 void* ret = allocate(n);
49 if (!ret)
50 throw std::bad_alloc();
51 return ret;
54 void* operator new[](std::size_t n) throw (std::bad_alloc)
56 void* ret = allocate(n);
57 if (!ret)
58 throw std::bad_alloc();
59 return ret;
62 void operator delete(void* p) throw()
64 deallocate(p);
67 void operator delete[](void* p) throw()
69 deallocate(p);
72 void* operator new(std::size_t n, const std::nothrow_t&) throw()
74 return allocate(n);
77 void* operator new[](std::size_t n, const std::nothrow_t&) throw()
79 return allocate(n);
82 void operator delete(void* p, const std::nothrow_t&) throw()
84 deallocate(p);
87 void operator delete[](void* p, const std::nothrow_t&) throw()
89 deallocate(p);
92 // libstdc++/12352
93 void test01(int iters)
95 bool test __attribute__((unused)) = true;
97 for (int j = 0; j < iters; ++j)
99 for (int i = 0; i < 100; ++i)
101 times_to_fail = i;
104 std::locale loc1 = __gnu_test::try_named_locale("");
105 std::locale loc2(loc1, std::locale::classic(),
106 std::locale::numeric);
108 catch (std::exception&)
115 int main(int argc, char* argv[])
117 int iters = 1;
118 if (argc > 1)
119 iters = std::atoi(argv[1]);
120 if (iters < 1)
121 iters = 1;
122 test01(iters);
124 return 0;