Debian Codegraph @

libstdc++-v3/testsuite/util/testsuite_shared.cc

raw
1 // Copyright (C) 2004-2025 Free Software Foundation, Inc.
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 3, or (at your option)
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
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 #include <string>
19 #include <stdexcept>
20 #include <iostream>
21 #include <sstream>
22 #include <set>
23 #include <map>
24 #include <ext/mt_allocator.h>
25 #include <bits/functexcept.h>
26 #if __cpp_rtti
27 # include <typeinfo>
28 #endif
29
30 namespace __gnu_test
31 {
32 // libstdc++/22309
33 extern "C" void
34 try_allocation()
35 {
36 typedef char value_t;
37
38 typedef __gnu_cxx::__mt_alloc<value_t> allocator_t;
39
40 typedef std::char_traits<value_t> traits_t;
41 typedef std::basic_string<value_t, traits_t, allocator_t> string_t;
42
43 string_t s;
44 s += "west beach, indiana dunes";
45 }
46
47 // libstdc++/23591
48 extern "C" void
49 try_throw_exception()
50 {
51 #if __cpp_exceptions
52 try
53 {
54 std::__throw_bad_exception();
55 }
56 catch (const std::exception& e)
57 { }
58 #endif
59 }
60
61 extern "C" void
62 try_function_random_fail()
63 {
64 long seed = lrand48();
65 if (seed < 2000)
66 seed = 2000;
67
68 {
69 std::ostringstream s;
70 s << "random_throw, seed: " << seed << std::endl;
71 std::cout << s.str();
72 }
73
74 while (--seed > 0)
75 {
76 try_throw_exception();
77 }
78
79 // Randomly throw. See if other threads cleanup.
80 std::__throw_bad_exception();
81 }
82
83 #if __cplusplus >= 201103L
84 # error "must be compiled with C++98"
85 #else
86 void
87 erase_external(std::set<int>& s)
88 { s.erase(s.begin()); }
89
90 void
91 erase_external(std::multiset<int>& s)
92 { s.erase(s.begin()); }
93
94 void
95 erase_external(std::map<int, int>& s)
96 { s.erase(s.begin()); }
97
98 void
99 erase_external(std::multimap<int, int>& s)
100 { s.erase(s.begin()); }
101
102 void
103 erase_external_iterators(std::set<int>& s)
104 {
105 typedef typename std::set<int>::iterator iterator_type;
106 iterator_type iter = s.begin();
107 s.erase(iter, ++iter);
108 }
109
110 void
111 erase_external_iterators(std::multiset<int>& s)
112 {
113 typedef typename std::multiset<int>::iterator iterator_type;
114 iterator_type iter = s.begin();
115 s.erase(iter, ++iter);
116 }
117
118 void
119 erase_external_iterators(std::map<int, int>& s)
120 {
121 typedef typename std::map<int, int>::iterator iterator_type;
122 iterator_type iter = s.begin();
123 s.erase(iter, ++iter);
124 }
125
126
127 void
128 erase_external_iterators(std::multimap<int, int>& s)
129 {
130 typedef typename std::multimap<int, int>::iterator iterator_type;
131 iterator_type iter = s.begin();
132 s.erase(iter, ++iter);
133 }
134 #endif
135
136 #if __cpp_rtti
137 // PR libstdc++/103240
138 namespace
139 {
140 struct S { };
141 }
142 const std::type_info& pr103240_private_S = typeid(S);
143 #endif
144
145 } // end namepace __gnu_test