uncaught_exceptions.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // XFAIL: with_system_cxx_lib=macosx10.12
  17. // XFAIL: with_system_cxx_lib=macosx10.13
  18. // test uncaught_exceptions
  19. #include <exception>
  20. #include <cassert>
  21. struct Uncaught {
  22. Uncaught(int depth) : d_(depth) {}
  23. ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
  24. int d_;
  25. };
  26. struct Outer {
  27. Outer(int depth) : d_(depth) {}
  28. ~Outer() {
  29. try {
  30. assert(std::uncaught_exceptions() == d_);
  31. Uncaught u(d_+1);
  32. throw 2;
  33. }
  34. catch (int) {}
  35. }
  36. int d_;
  37. };
  38. int main () {
  39. assert(std::uncaught_exceptions() == 0);
  40. {
  41. Outer o(0);
  42. }
  43. assert(std::uncaught_exceptions() == 0);
  44. {
  45. try {
  46. Outer o(1);
  47. throw 1;
  48. }
  49. catch (int) {
  50. assert(std::uncaught_exceptions() == 0);
  51. }
  52. }
  53. assert(std::uncaught_exceptions() == 0);
  54. }