debug_throw.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: libcpp-no-exceptions
  10. // MODULES_DEFINES: _LIBCPP_DEBUG=0
  11. // Can't test the system lib because this test enables debug mode
  12. // UNSUPPORTED: with_system_cxx_lib
  13. // Test that the default debug handler can be overridden and test the
  14. // throwing debug handler.
  15. #define _LIBCPP_DEBUG 0
  16. #include <cstdlib>
  17. #include <exception>
  18. #include <type_traits>
  19. #include <__debug>
  20. int main(int, char**)
  21. {
  22. {
  23. std::__libcpp_debug_function = std::__libcpp_throw_debug_function;
  24. try {
  25. _LIBCPP_ASSERT(false, "foo");
  26. } catch (std::__libcpp_debug_exception const&) {}
  27. }
  28. {
  29. // test that the libc++ exception type derives from std::exception
  30. static_assert((std::is_base_of<std::exception,
  31. std::__libcpp_debug_exception
  32. >::value), "must be an exception");
  33. }
  34. return 0;
  35. }