make_exception_ptr.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // UNSUPPORTED: libcpp-no-exceptions
  10. // <exception>
  11. // template<class E> exception_ptr make_exception_ptr(E e);
  12. #include <exception>
  13. #include <cassert>
  14. struct A
  15. {
  16. static int constructed;
  17. int data_;
  18. A(int data = 0) : data_(data) {++constructed;}
  19. ~A() {--constructed;}
  20. A(const A& a) : data_(a.data_) {++constructed;}
  21. };
  22. int A::constructed = 0;
  23. int main()
  24. {
  25. {
  26. std::exception_ptr p = std::make_exception_ptr(A(5));
  27. try
  28. {
  29. std::rethrow_exception(p);
  30. assert(false);
  31. }
  32. catch (const A& a)
  33. {
  34. assert(A::constructed == 1);
  35. assert(p != nullptr);
  36. p = nullptr;
  37. assert(p == nullptr);
  38. assert(a.data_ == 5);
  39. assert(A::constructed == 1);
  40. }
  41. assert(A::constructed == 0);
  42. }
  43. }