ctor_default.pass.cpp 1.1 KB

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