]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stacktrace/example/assert_handler.cpp
1 // Copyright Antony Polukhin, 2016-2020.
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #define BOOST_ENABLE_ASSERT_HANDLER
9 #include <cstdlib> // std::exit
10 #include <boost/array.hpp>
11 BOOST_NOINLINE
void foo(int i
);
12 BOOST_NOINLINE
void bar(int i
);
14 BOOST_NOINLINE
void bar(int i
) {
15 boost::array
<int, 5> a
= {{101, 100, 123, 23, 32}};
23 BOOST_NOINLINE
void foo(int i
) {
27 //[getting_started_assert_handlers
29 // BOOST_ENABLE_ASSERT_DEBUG_HANDLER is defined for the whole project
30 #include <stdexcept> // std::logic_error
31 #include <iostream> // std::cerr
32 #include <boost/stacktrace.hpp>
35 inline void assertion_failed_msg(char const* expr
, char const* msg
, char const* function
, char const* /*file*/, long /*line*/) {
36 std::cerr
<< "Expression '" << expr
<< "' is false in function '" << function
<< "': " << (msg
? msg
: "<...>") << ".\n"
37 << "Backtrace:\n" << boost::stacktrace::stacktrace() << '\n';
38 /*<-*/ std::exit(0); /*->*/
42 inline void assertion_failed(char const* expr
, char const* function
, char const* file
, long line
) {
43 ::boost::assertion_failed_msg(expr
, 0 /*nullptr*/, function
, file
, line
);