assign.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // XFAIL: libcpp-no-exceptions
  10. // <exception>
  11. // class nested_exception;
  12. // nested_exception& operator=(const nested_exception&) throw() = default;
  13. #include <exception>
  14. #include <cassert>
  15. class A
  16. {
  17. int data_;
  18. public:
  19. explicit A(int data) : data_(data) {}
  20. friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
  21. };
  22. int main()
  23. {
  24. {
  25. std::nested_exception e0;
  26. std::nested_exception e;
  27. e = e0;
  28. assert(e.nested_ptr() == nullptr);
  29. }
  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. }