ctor_default.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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() throw();
  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 e;
  25. assert(e.nested_ptr() == nullptr);
  26. }
  27. #ifndef TEST_HAS_NO_EXCEPTIONS
  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. #endif
  50. return 0;
  51. }