ctor_copy.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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(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 = e0;
  26. assert(e.nested_ptr() == nullptr);
  27. }
  28. {
  29. try
  30. {
  31. throw A(2);
  32. assert(false);
  33. }
  34. catch (const A&)
  35. {
  36. std::nested_exception e0;
  37. std::nested_exception e = e0;
  38. assert(e.nested_ptr() != nullptr);
  39. try
  40. {
  41. rethrow_exception(e.nested_ptr());
  42. assert(false);
  43. }
  44. catch (const A& a)
  45. {
  46. assert(a == A(2));
  47. }
  48. }
  49. }
  50. }