2 // boost/assert.hpp - BOOST_ASSERT(expr)
3 // BOOST_ASSERT_MSG(expr, msg)
6 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
7 // Copyright (c) 2007 Peter Dimov
8 // Copyright (c) Beman Dawes 2011
10 // Distributed under the Boost Software License, Version 1.0. (See
11 // accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 // Note: There are no include guards. This is intentional.
16 // See http://www.boost.org/libs/utility/assert.html for documentation.
20 // Stop inspect complaining about use of 'assert':
22 // boostinspect:naassert_macro
25 //--------------------------------------------------------------------------------------//
27 //--------------------------------------------------------------------------------------//
31 #if defined(BOOST_DISABLE_ASSERTS)
33 # define BOOST_ASSERT(expr) ((void)0)
35 #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
37 #include <boost/config.hpp>
38 #include <boost/current_function.hpp>
42 void assertion_failed(char const * expr,
43 char const * function, char const * file, long line); // user defined
46 #define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr)) \
48 : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
51 # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
52 # define BOOST_ASSERT(expr) assert(expr)
55 //--------------------------------------------------------------------------------------//
56 // BOOST_ASSERT_MSG //
57 //--------------------------------------------------------------------------------------//
59 # undef BOOST_ASSERT_MSG
61 #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
63 #define BOOST_ASSERT_MSG(expr, msg) ((void)0)
65 #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
67 #include <boost/config.hpp>
68 #include <boost/current_function.hpp>
72 void assertion_failed_msg(char const * expr, char const * msg,
73 char const * function, char const * file, long line); // user defined
76 #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \
78 : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
81 #ifndef BOOST_ASSERT_HPP
82 #define BOOST_ASSERT_HPP
85 #include <boost/config.hpp>
86 #include <boost/current_function.hpp>
88 // IDE's like Visual Studio perform better if output goes to std::cout or
89 // some other stream, so allow user to configure output stream:
90 #ifndef BOOST_ASSERT_MSG_OSTREAM
91 # define BOOST_ASSERT_MSG_OSTREAM std::cerr
100 // Note: The template is needed to make the function non-inline and avoid linking errors
101 template< typename CharT >
102 BOOST_NOINLINE void assertion_failed_msg(CharT const * expr, char const * msg, char const * function,
103 char const * file, long line)
105 BOOST_ASSERT_MSG_OSTREAM
106 << "***** Internal Program Error - assertion (" << expr << ") failed in "
108 << file << '(' << line << "): " << msg << std::endl;
110 // The Windows CE CRT library does not have abort() so use exit(-1) instead.
121 #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \
123 : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \
124 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
127 //--------------------------------------------------------------------------------------//
129 //--------------------------------------------------------------------------------------//
133 #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
135 # define BOOST_VERIFY(expr) ((void)(expr))
139 # define BOOST_VERIFY(expr) BOOST_ASSERT(expr)