12352.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // { dg-require-namedlocale "" }
  2. // { dg-require-namedlocale "en_US.ISO8859-1" }
  3. // Copyright (C) 2003-2022 Free Software Foundation, Inc.
  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 3, or (at your option)
  9. // any later version.
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  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. // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
  18. #include <new>
  19. #include <locale>
  20. #include <cstdlib>
  21. #include <cstring>
  22. #include <testsuite_hooks.h>
  23. int times_to_fail = 0;
  24. void* allocate(std::size_t n)
  25. {
  26. if (!times_to_fail--)
  27. return 0;
  28. void* ret = std::malloc(n ? n : 1);
  29. if (ret)
  30. std::memset(ret, 0xbc, n);
  31. return ret;
  32. }
  33. void deallocate(void* p)
  34. {
  35. if (p)
  36. std::free(p);
  37. }
  38. void* operator new(std::size_t n) THROW (std::bad_alloc)
  39. {
  40. void* ret = allocate(n);
  41. if (!ret)
  42. throw std::bad_alloc();
  43. return ret;
  44. }
  45. void* operator new[](std::size_t n) THROW (std::bad_alloc)
  46. {
  47. void* ret = allocate(n);
  48. if (!ret)
  49. throw std::bad_alloc();
  50. return ret;
  51. }
  52. void operator delete(void* p) throw()
  53. {
  54. deallocate(p);
  55. }
  56. void operator delete[](void* p) throw()
  57. {
  58. deallocate(p);
  59. }
  60. #if __cpp_sized_deallocation
  61. void operator delete(void* p, std::size_t) throw()
  62. {
  63. deallocate(p);
  64. }
  65. void operator delete[](void* p, std::size_t) throw()
  66. {
  67. deallocate(p);
  68. }
  69. #endif
  70. void* operator new(std::size_t n, const std::nothrow_t&) throw()
  71. {
  72. return allocate(n);
  73. }
  74. void* operator new[](std::size_t n, const std::nothrow_t&) throw()
  75. {
  76. return allocate(n);
  77. }
  78. void operator delete(void* p, const std::nothrow_t&) throw()
  79. {
  80. deallocate(p);
  81. }
  82. void operator delete[](void* p, const std::nothrow_t&) throw()
  83. {
  84. deallocate(p);
  85. }
  86. // libstdc++/12352
  87. void test01(int iters)
  88. {
  89. for (int j = 0; j < iters; ++j)
  90. {
  91. for (int i = 0; i < 100; ++i)
  92. {
  93. times_to_fail = i;
  94. try
  95. {
  96. std::locale loc1 = std::locale("");
  97. std::locale loc2(loc1, std::locale::classic(),
  98. std::locale::numeric);
  99. std::locale loc3 = std::locale(ISO_8859(1,en_US));
  100. std::locale loc4(loc3, std::locale::classic(),
  101. std::locale::numeric);
  102. }
  103. catch (std::exception&)
  104. {
  105. }
  106. }
  107. }
  108. }
  109. int main(int argc, char* argv[])
  110. {
  111. int iters = 1;
  112. if (argc > 1)
  113. iters = std::atoi(argv[1]);
  114. if (iters < 1)
  115. iters = 1;
  116. test01(iters);
  117. return 0;
  118. }