]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_shared.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_shared.cc
1 // Copyright (C) 2004-2019 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
27 namespace __gnu_test
28 {
29 // libstdc++/22309
30 extern "C" void
31 try_allocation()
32 {
33 typedef char value_t;
34
35 typedef __gnu_cxx::__mt_alloc<value_t> allocator_t;
36
37 typedef std::char_traits<value_t> traits_t;
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 }
43
44 // libstdc++/23591
45 extern "C" void
46 try_throw_exception()
47 {
48 try
49 {
50 std::__throw_bad_exception();
51 }
52 catch (const std::exception& e)
53 { }
54 }
55
56 extern "C" void
57 try_function_random_fail()
58 {
59 long seed = lrand48();
60 if (seed < 2000)
61 seed = 2000;
62
63 {
64 std::ostringstream s;
65 s << "random_throw, seed: " << seed << std::endl;
66 std::cout << s.str();
67 }
68
69 while (--seed > 0)
70 {
71 try_throw_exception();
72 }
73
74 // Randomly throw. See if other threads cleanup.
75 std::__throw_bad_exception();
76 }
77
78 #if __cplusplus < 201103L
79 // "must be compiled with C++98"
80 void
81 erase_external(std::set<int>& s)
82 { s.erase(s.begin()); }
83
84 void
85 erase_external(std::multiset<int>& s)
86 { s.erase(s.begin()); }
87
88 void
89 erase_external(std::map<int, int>& s)
90 { s.erase(s.begin()); }
91
92 void
93 erase_external(std::multimap<int, int>& s)
94 { s.erase(s.begin()); }
95
96 void
97 erase_external_iterators(std::set<int>& s)
98 {
99 typedef typename std::set<int>::iterator iterator_type;
100 iterator_type iter = s.begin();
101 s.erase(iter, ++iter);
102 }
103
104 void
105 erase_external_iterators(std::multiset<int>& s)
106 {
107 typedef typename std::multiset<int>::iterator iterator_type;
108 iterator_type iter = s.begin();
109 s.erase(iter, ++iter);
110 }
111
112 void
113 erase_external_iterators(std::map<int, int>& s)
114 {
115 typedef typename std::map<int, int>::iterator iterator_type;
116 iterator_type iter = s.begin();
117 s.erase(iter, ++iter);
118 }
119
120
121 void
122 erase_external_iterators(std::multimap<int, int>& s)
123 {
124 typedef typename std::multimap<int, int>::iterator iterator_type;
125 iterator_type iter = s.begin();
126 s.erase(iter, ++iter);
127 }
128 #endif
129
130 } // end namepace __gnu_test