ctor_default.pass.cpp 1.2 KB

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