uncaught_exceptions.pass.cpp 945 B

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