ctor_copy.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <exception>
  9. // class nested_exception;
  10. // nested_exception(const nested_exception&) throw() = default;
  11. #include <exception>
  12. #include <cassert>
  13. #include "test_macros.h"
  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(int, char**)
  22. {
  23. {
  24. std::nested_exception e0;
  25. std::nested_exception e = e0;
  26. assert(e.nested_ptr() == nullptr);
  27. }
  28. #ifndef TEST_HAS_NO_EXCEPTIONS
  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. #endif
  52. return 0;
  53. }