1 | //
|
---|
2 | // boost/assert.hpp - BOOST_ASSERT(expr)
|
---|
3 | // BOOST_ASSERT_MSG(expr, msg)
|
---|
4 | // BOOST_VERIFY(expr)
|
---|
5 | //
|
---|
6 | // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
|
---|
7 | // Copyright (c) 2007 Peter Dimov
|
---|
8 | // Copyright (c) Beman Dawes 2011
|
---|
9 | //
|
---|
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)
|
---|
13 | //
|
---|
14 | // Note: There are no include guards. This is intentional.
|
---|
15 | //
|
---|
16 | // See http://www.boost.org/libs/utility/assert.html for documentation.
|
---|
17 | //
|
---|
18 |
|
---|
19 | //
|
---|
20 | // Stop inspect complaining about use of 'assert':
|
---|
21 | //
|
---|
22 | // boostinspect:naassert_macro
|
---|
23 | //
|
---|
24 |
|
---|
25 | //--------------------------------------------------------------------------------------//
|
---|
26 | // BOOST_ASSERT //
|
---|
27 | //--------------------------------------------------------------------------------------//
|
---|
28 |
|
---|
29 | #undef BOOST_ASSERT
|
---|
30 |
|
---|
31 | #if defined(BOOST_DISABLE_ASSERTS)
|
---|
32 |
|
---|
33 | # define BOOST_ASSERT(expr) ((void)0)
|
---|
34 |
|
---|
35 | #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
|
---|
36 |
|
---|
37 | #include <boost/current_function.hpp>
|
---|
38 |
|
---|
39 | namespace boost
|
---|
40 | {
|
---|
41 | void assertion_failed(char const * expr,
|
---|
42 | char const * function, char const * file, long line); // user defined
|
---|
43 | } // namespace boost
|
---|
44 |
|
---|
45 | // BOOST_CURRENT_FUNCTION can produce very long names, that may lead to huge size of output files.
|
---|
46 | // So allow user to define current function macro (for example to shorter __FUNCTION__
|
---|
47 | // macro or to "(unknown)")
|
---|
48 | #ifndef BOOST_ASSERT_CURRENT_FUNCTION_NAME
|
---|
49 | # define BOOST_ASSERT_CURRENT_FUNCTION_NAME BOOST_CURRENT_FUNCTION
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #define BOOST_ASSERT(expr) ((expr) \
|
---|
53 | ? ((void)0) \
|
---|
54 | : ::boost::assertion_failed(#expr, BOOST_ASSERT_CURRENT_FUNCTION_NAME, __FILE__, __LINE__))
|
---|
55 |
|
---|
56 | #else
|
---|
57 | # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
|
---|
58 | # define BOOST_ASSERT(expr) assert(expr)
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | //--------------------------------------------------------------------------------------//
|
---|
62 | // BOOST_ASSERT_MSG //
|
---|
63 | //--------------------------------------------------------------------------------------//
|
---|
64 |
|
---|
65 | # undef BOOST_ASSERT_MSG
|
---|
66 |
|
---|
67 | #if !defined(BOOST_DISABLE_ASSERTS) && !defined(NDEBUG)
|
---|
68 |
|
---|
69 | // BOOST_CURRENT_FUNCTION can produce very long names, that may lead to huge size of output files.
|
---|
70 | // So allow user to define current function macro (for example to shorter __FUNCTION__
|
---|
71 | // macro or to "(unknown)")
|
---|
72 | #ifndef BOOST_ASSERT_MSG_CURRENT_FUNCTION_NAME
|
---|
73 | # define BOOST_ASSERT_MSG_CURRENT_FUNCTION_NAME BOOST_CURRENT_FUNCTION
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
|
---|
79 |
|
---|
80 | #define BOOST_ASSERT_MSG(expr, msg) ((void)0)
|
---|
81 |
|
---|
82 | #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
|
---|
83 |
|
---|
84 | #include <boost/current_function.hpp>
|
---|
85 |
|
---|
86 | namespace boost
|
---|
87 | {
|
---|
88 | void assertion_failed_msg(char const * expr, char const * msg,
|
---|
89 | char const * function, char const * file, long line); // user defined
|
---|
90 | } // namespace boost
|
---|
91 |
|
---|
92 | #define BOOST_ASSERT_MSG(expr, msg) ((expr) \
|
---|
93 | ? ((void)0) \
|
---|
94 | : ::boost::assertion_failed_msg(#expr, msg, BOOST_ASSERT_MSG_CURRENT_FUNCTION_NAME, __FILE__, __LINE__))
|
---|
95 |
|
---|
96 | #else
|
---|
97 | #ifndef BOOST_ASSERT_HPP
|
---|
98 | #define BOOST_ASSERT_HPP
|
---|
99 | #include <cstdlib>
|
---|
100 | #include <iostream>
|
---|
101 | #include <boost/current_function.hpp>
|
---|
102 |
|
---|
103 | // IDE's like Visual Studio perform better if output goes to std::cout or
|
---|
104 | // some other stream, so allow user to configure output stream:
|
---|
105 | #ifndef BOOST_ASSERT_MSG_OSTREAM
|
---|
106 | # define BOOST_ASSERT_MSG_OSTREAM std::cerr
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | namespace boost
|
---|
110 | {
|
---|
111 | namespace assertion
|
---|
112 | {
|
---|
113 | namespace detail
|
---|
114 | {
|
---|
115 | inline void assertion_failed_msg(char const * expr, char const * msg, char const * function,
|
---|
116 | char const * file, long line)
|
---|
117 | {
|
---|
118 | BOOST_ASSERT_MSG_OSTREAM
|
---|
119 | << "***** Internal Program Error - assertion (" << expr << ") failed in "
|
---|
120 | << function << ":\n"
|
---|
121 | << file << '(' << line << "): " << msg << std::endl;
|
---|
122 | #ifdef UNDER_CE
|
---|
123 | // The Windows CE CRT library does not have abort() so use exit(-1) instead.
|
---|
124 | std::exit(-1);
|
---|
125 | #else
|
---|
126 | std::abort();
|
---|
127 | #endif
|
---|
128 | }
|
---|
129 | } // detail
|
---|
130 | } // assertion
|
---|
131 | } // detail
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | #define BOOST_ASSERT_MSG(expr, msg) ((expr) \
|
---|
135 | ? ((void)0) \
|
---|
136 | : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \
|
---|
137 | BOOST_ASSERT_MSG_CURRENT_FUNCTION_NAME, __FILE__, __LINE__))
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | //--------------------------------------------------------------------------------------//
|
---|
141 | // BOOST_VERIFY //
|
---|
142 | //--------------------------------------------------------------------------------------//
|
---|
143 |
|
---|
144 | #undef BOOST_VERIFY
|
---|
145 |
|
---|
146 | #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
|
---|
147 |
|
---|
148 | # define BOOST_VERIFY(expr) ((void)(expr))
|
---|
149 |
|
---|
150 | #else
|
---|
151 |
|
---|
152 | # define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
|
---|
153 |
|
---|
154 | #endif
|
---|