Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / testsuite / 22_locale / locale / cons / 12352.cc
blobcaad92f80de3ea893a9523f76c2416a0d56f2ade
1 // { dg-require-namedlocale "" }
3 // Copyright (C) 2003, 2005 Free Software Foundation
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
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
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 COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
23 #include <new>
24 #include <locale>
25 #include <cstdlib>
26 #include <cstring>
27 #include <testsuite_hooks.h>
29 int times_to_fail = 0;
31 void* allocate(std::size_t n)
33 if (!times_to_fail--)
34 return 0;
36 void* ret = std::malloc(n ? n : 1);
37 if (ret)
38 std::memset(ret, 0xbc, n);
39 return ret;
42 void deallocate(void* p)
44 if (p)
45 std::free(p);
48 void* operator new(std::size_t n) throw (std::bad_alloc)
50 void* ret = allocate(n);
51 if (!ret)
52 throw std::bad_alloc();
53 return ret;
56 void* operator new[](std::size_t n) throw (std::bad_alloc)
58 void* ret = allocate(n);
59 if (!ret)
60 throw std::bad_alloc();
61 return ret;
64 void operator delete(void* p) throw()
66 deallocate(p);
69 void operator delete[](void* p) throw()
71 deallocate(p);
74 void* operator new(std::size_t n, const std::nothrow_t&) throw()
76 return allocate(n);
79 void* operator new[](std::size_t n, const std::nothrow_t&) throw()
81 return allocate(n);
84 void operator delete(void* p, const std::nothrow_t&) throw()
86 deallocate(p);
89 void operator delete[](void* p, const std::nothrow_t&) throw()
91 deallocate(p);
94 // libstdc++/12352
95 void test01(int iters)
97 bool test __attribute__((unused)) = true;
99 for (int j = 0; j < iters; ++j)
101 for (int i = 0; i < 100; ++i)
103 times_to_fail = i;
106 std::locale loc1 = std::locale("");
107 std::locale loc2(loc1, std::locale::classic(),
108 std::locale::numeric);
110 catch (std::exception&)
117 int main(int argc, char* argv[])
119 int iters = 1;
120 if (argc > 1)
121 iters = std::atoi(argv[1]);
122 if (iters < 1)
123 iters = 1;
124 test01(iters);
126 return 0;