uncaught_exception.pass.cpp 868 B

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