]> git.donarmstrong.com Git - rsem.git/blob - boost/assert.hpp
Updated boost to v1.55.0
[rsem.git] / boost / assert.hpp
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/config.hpp>
38 #include <boost/current_function.hpp>
39
40 namespace boost
41 {
42   void assertion_failed(char const * expr,
43                         char const * function, char const * file, long line); // user defined
44 } // namespace boost
45
46 #define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr)) \
47   ? ((void)0) \
48   : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
49
50 #else
51 # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
52 # define BOOST_ASSERT(expr) assert(expr)
53 #endif
54
55 //--------------------------------------------------------------------------------------//
56 //                                   BOOST_ASSERT_MSG                                   //
57 //--------------------------------------------------------------------------------------//
58
59 # undef BOOST_ASSERT_MSG
60
61 #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
62
63   #define BOOST_ASSERT_MSG(expr, msg) ((void)0)
64
65 #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
66
67   #include <boost/config.hpp>
68   #include <boost/current_function.hpp>
69
70   namespace boost
71   {
72     void assertion_failed_msg(char const * expr, char const * msg,
73                               char const * function, char const * file, long line); // user defined
74   } // namespace boost
75
76   #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \
77     ? ((void)0) \
78     : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
79
80 #else
81   #ifndef BOOST_ASSERT_HPP
82     #define BOOST_ASSERT_HPP
83     #include <cstdlib>
84     #include <iostream>
85     #include <boost/config.hpp>
86     #include <boost/current_function.hpp>
87
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
92     #endif
93
94     namespace boost
95     {
96       namespace assertion
97       {
98         namespace detail
99         {
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)
104           {
105             BOOST_ASSERT_MSG_OSTREAM
106               << "***** Internal Program Error - assertion (" << expr << ") failed in "
107               << function << ":\n"
108               << file << '(' << line << "): " << msg << std::endl;
109 #ifdef UNDER_CE
110             // The Windows CE CRT library does not have abort() so use exit(-1) instead.
111             std::exit(-1);
112 #else
113             std::abort();
114 #endif
115           }
116         } // detail
117       } // assertion
118     } // detail
119   #endif
120
121   #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \
122     ? ((void)0) \
123     : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \
124           BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
125 #endif
126
127 //--------------------------------------------------------------------------------------//
128 //                                     BOOST_VERIFY                                     //
129 //--------------------------------------------------------------------------------------//
130
131 #undef BOOST_VERIFY
132
133 #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
134
135 # define BOOST_VERIFY(expr) ((void)(expr))
136
137 #else
138
139 # define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
140
141 #endif