mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-21 15:10:37 +08:00

This patch implements changes to allow _LIBCPP_ASSERT to throw on failure instead of aborting. The main changes needed to do this are: 1. Change _LIBCPP_ASSERT to call a handler via a replacable function pointer instead of calling abort directly. Additionally this patch implements two handler functions, one which aborts and another that throws an exception. 2. Add _NOEXCEPT_DEBUG macro for disabling noexcept spec on function which contain _LIBCPP_ASSERT. This is required in order to prevent assertion failures throwing through a noexcept function. This macro has no effect unless _LIBCPP_DEBUG_USE_EXCEPTIONS is defined. Having a non-aborting _LIBCPP_ASSERT is very important to allow sane testing of debug mode. Currently we can only have one test case per file, since the test case will cause the program to abort. Testing debug mode this way would require thousands of test files, most of which would be 95% boiler plate. I don't think this is a feasible strategy. Fortunately using a throwing debug handler solves these issues. Additionally this patch rewrites the documentation for debug mode. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290651 91177308-0d34-0410-b5e6-96231b3b80d8
31 lines
767 B
C++
31 lines
767 B
C++
// -*- C++ -*-
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// Test that the default debug handler aborts the program.
|
|
|
|
#define _LIBCPP_DEBUG 0
|
|
|
|
#include <csignal>
|
|
#include <cstdlib>
|
|
#include <__debug>
|
|
|
|
void signal_handler(int signal)
|
|
{
|
|
if (signal == SIGABRT)
|
|
std::_Exit(EXIT_SUCCESS);
|
|
std::_Exit(EXIT_FAILURE);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
if (std::signal(SIGABRT, signal_handler) != SIG_ERR)
|
|
_LIBCPP_ASSERT(false, "foo");
|
|
return EXIT_FAILURE;
|
|
}
|