assign.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <exception>
  10. // class nested_exception;
  11. // nested_exception& operator=(const nested_exception&) throw() = default;
  12. #include <exception>
  13. #include <cassert>
  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()
  22. {
  23. {
  24. std::nested_exception e0;
  25. std::nested_exception e;
  26. e = e0;
  27. assert(e.nested_ptr() == nullptr);
  28. }
  29. {
  30. try
  31. {
  32. throw A(2);
  33. assert(false);
  34. }
  35. catch (const A&)
  36. {
  37. std::nested_exception e0;
  38. std::nested_exception e;
  39. e = e0;
  40. assert(e.nested_ptr() != nullptr);
  41. try
  42. {
  43. rethrow_exception(e.nested_ptr());
  44. assert(false);
  45. }
  46. catch (const A& a)
  47. {
  48. assert(a == A(2));
  49. }
  50. }
  51. }
  52. }