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