uncaught_exceptions.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // XFAIL: libcpp-no-exceptions
  11. // XFAIL: availability=macosx10.7
  12. // XFAIL: availability=macosx10.8
  13. // XFAIL: availability=macosx10.9
  14. // XFAIL: availability=macosx10.10
  15. // XFAIL: availability=macosx10.11
  16. // test uncaught_exceptions
  17. #include <exception>
  18. #include <cassert>
  19. struct A
  20. {
  21. ~A()
  22. {
  23. assert(std::uncaught_exceptions() > 0);
  24. }
  25. };
  26. struct B
  27. {
  28. B()
  29. {
  30. // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475
  31. assert(std::uncaught_exceptions() == 0);
  32. }
  33. };
  34. int main()
  35. {
  36. try
  37. {
  38. A a;
  39. assert(std::uncaught_exceptions() == 0);
  40. throw B();
  41. }
  42. catch (...)
  43. {
  44. assert(std::uncaught_exception() == 0);
  45. }
  46. assert(std::uncaught_exceptions() == 0);
  47. }