ctor_copy.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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(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 = 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 = e0;
  39. assert(e.nested_ptr() != nullptr);
  40. try
  41. {
  42. rethrow_exception(e.nested_ptr());
  43. assert(false);
  44. }
  45. catch (const A& a)
  46. {
  47. assert(a == A(2));
  48. }
  49. }
  50. }
  51. }