92124.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (C) 2020-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. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License along
  13. // with this library; see the file COPYING3. If not see
  14. // <http://www.gnu.org/licenses/>.
  15. // { dg-do run { target c++11 } }
  16. #include <set>
  17. #include <testsuite_allocator.h>
  18. struct X
  19. {
  20. X(int i) noexcept(true) : _i(i) { }
  21. X(const X& x) noexcept(false)
  22. {
  23. if (Throw) throw 0;
  24. _i = x._i;
  25. }
  26. // Move constructor might throw
  27. X(X&& x) noexcept(false)
  28. {
  29. _i = x._i;
  30. x._i = -x._i;
  31. }
  32. // Tracking calls to assignment functions
  33. X& operator=(const X&) { throw 1; }
  34. X& operator=(X&& x) noexcept(false)
  35. {
  36. _i = x._i;
  37. x._i = -x._i;
  38. return *this;
  39. }
  40. bool
  41. operator < (const X& x) const
  42. { return _i < x._i; }
  43. int _i;
  44. static bool Throw;
  45. };
  46. bool X::Throw = false;
  47. void
  48. test01()
  49. {
  50. using A = __gnu_test::propagating_allocator<X, false>;
  51. A a1(1), a2(2);
  52. std::set<X, std::less<X>, A> s1({ X(1) }, a1), s2({ X(2) }, a2);
  53. X::Throw = true;
  54. s1 = std::move(s2);
  55. }
  56. int
  57. main()
  58. {
  59. test01();
  60. }