]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2004-2021 Free Software Foundation, Inc. |
2f9f6cef BK |
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 | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
2f9f6cef BK |
7 | // any later version. |
8 | // | |
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. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
2f9f6cef BK |
17 | |
18 | #include <string> | |
cddfb1c7 BK |
19 | #include <stdexcept> |
20 | #include <iostream> | |
21 | #include <sstream> | |
3b31a727 BK |
22 | #include <set> |
23 | #include <map> | |
2f9f6cef | 24 | #include <ext/mt_allocator.h> |
949d9ae1 | 25 | #include <bits/functexcept.h> |
2f9f6cef | 26 | |
3b31a727 BK |
27 | namespace __gnu_test |
28 | { | |
2f9f6cef BK |
29 | // libstdc++/22309 |
30 | extern "C" void | |
cddfb1c7 | 31 | try_allocation() |
2f9f6cef BK |
32 | { |
33 | typedef char value_t; | |
34 | ||
dcdf969d | 35 | typedef __gnu_cxx::__mt_alloc<value_t> allocator_t; |
2f9f6cef | 36 | |
f92ab29f | 37 | typedef std::char_traits<value_t> traits_t; |
2f9f6cef BK |
38 | typedef std::basic_string<value_t, traits_t, allocator_t> string_t; |
39 | ||
40 | string_t s; | |
41 | s += "west beach, indiana dunes"; | |
42 | } | |
cddfb1c7 BK |
43 | |
44 | // libstdc++/23591 | |
f92ab29f | 45 | extern "C" void |
cddfb1c7 BK |
46 | try_throw_exception() |
47 | { | |
4c27c658 | 48 | #if __cpp_exceptions |
cddfb1c7 BK |
49 | try |
50 | { | |
949d9ae1 | 51 | std::__throw_bad_exception(); |
cddfb1c7 BK |
52 | } |
53 | catch (const std::exception& e) | |
54 | { } | |
4c27c658 | 55 | #endif |
cddfb1c7 BK |
56 | } |
57 | ||
f92ab29f | 58 | extern "C" void |
cddfb1c7 BK |
59 | try_function_random_fail() |
60 | { | |
61 | long seed = lrand48(); | |
62 | if (seed < 2000) | |
63 | seed = 2000; | |
64 | ||
65 | { | |
66 | std::ostringstream s; | |
67 | s << "random_throw, seed: " << seed << std::endl; | |
68 | std::cout << s.str(); | |
69 | } | |
70 | ||
71 | while (--seed > 0) | |
72 | { | |
73 | try_throw_exception(); | |
74 | } | |
75 | ||
76 | // Randomly throw. See if other threads cleanup. | |
949d9ae1 | 77 | std::__throw_bad_exception(); |
cddfb1c7 | 78 | } |
3b31a727 | 79 | |
4c27c658 JW |
80 | #if __cplusplus >= 201103L |
81 | # error "must be compiled with C++98" | |
82 | #else | |
f92ab29f | 83 | void |
3b31a727 BK |
84 | erase_external(std::set<int>& s) |
85 | { s.erase(s.begin()); } | |
86 | ||
f92ab29f | 87 | void |
3b31a727 BK |
88 | erase_external(std::multiset<int>& s) |
89 | { s.erase(s.begin()); } | |
f92ab29f CG |
90 | |
91 | void | |
3b31a727 BK |
92 | erase_external(std::map<int, int>& s) |
93 | { s.erase(s.begin()); } | |
f92ab29f CG |
94 | |
95 | void | |
3b31a727 BK |
96 | erase_external(std::multimap<int, int>& s) |
97 | { s.erase(s.begin()); } | |
98 | ||
f92ab29f | 99 | void |
3b31a727 BK |
100 | erase_external_iterators(std::set<int>& s) |
101 | { | |
102 | typedef typename std::set<int>::iterator iterator_type; | |
103 | iterator_type iter = s.begin(); | |
104 | s.erase(iter, ++iter); | |
105 | } | |
106 | ||
f92ab29f | 107 | void |
3b31a727 BK |
108 | erase_external_iterators(std::multiset<int>& s) |
109 | { | |
110 | typedef typename std::multiset<int>::iterator iterator_type; | |
111 | iterator_type iter = s.begin(); | |
112 | s.erase(iter, ++iter); | |
113 | } | |
114 | ||
f92ab29f | 115 | void |
3b31a727 BK |
116 | erase_external_iterators(std::map<int, int>& s) |
117 | { | |
118 | typedef typename std::map<int, int>::iterator iterator_type; | |
119 | iterator_type iter = s.begin(); | |
120 | s.erase(iter, ++iter); | |
121 | } | |
122 | ||
f92ab29f CG |
123 | |
124 | void | |
3b31a727 BK |
125 | erase_external_iterators(std::multimap<int, int>& s) |
126 | { | |
127 | typedef typename std::multimap<int, int>::iterator iterator_type; | |
128 | iterator_type iter = s.begin(); | |
129 | s.erase(iter, ++iter); | |
130 | } | |
131 | #endif | |
132 | ||
133 | } // end namepace __gnu_test |