testsuite_shared.cc 3.1 KB

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