assign.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <exception>
  9. // class nested_exception;
  10. // nested_exception& operator=(const nested_exception&) throw() = default;
  11. #include <exception>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. class A
  15. {
  16. int data_;
  17. public:
  18. explicit A(int data) : data_(data) {}
  19. friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
  20. };
  21. int main(int, char**)
  22. {
  23. {
  24. std::nested_exception e0;
  25. std::nested_exception e;
  26. e = e0;
  27. assert(e.nested_ptr() == nullptr);
  28. }
  29. #ifndef TEST_HAS_NO_EXCEPTIONS
  30. {
  31. try
  32. {
  33. throw A(2);
  34. assert(false);
  35. }
  36. catch (const A&)
  37. {
  38. std::nested_exception e0;
  39. std::nested_exception e;
  40. e = e0;
  41. assert(e.nested_ptr() != nullptr);
  42. try
  43. {
  44. rethrow_exception(e.nested_ptr());
  45. assert(false);
  46. }
  47. catch (const A& a)
  48. {
  49. assert(a == A(2));
  50. }
  51. }
  52. }
  53. #endif
  54. return 0;
  55. }