blob: 539857c4f367fe1b227754b46d21aa079349ca7d [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001//
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
Jeff Thompson2277ce52013-08-01 17:34:11 -070037#include <ndnboost/current_function.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070038
39namespace ndnboost
40{
41 void assertion_failed(char const * expr,
42 char const * function, char const * file, long line); // user defined
43} // namespace ndnboost
44
45#define BOOST_ASSERT(expr) ((expr) \
46 ? ((void)0) \
47 : ::ndnboost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
48
49#else
50# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
51# define BOOST_ASSERT(expr) assert(expr)
52#endif
53
54//--------------------------------------------------------------------------------------//
55// BOOST_ASSERT_MSG //
56//--------------------------------------------------------------------------------------//
57
58# undef BOOST_ASSERT_MSG
59
60#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
61
62 #define BOOST_ASSERT_MSG(expr, msg) ((void)0)
63
64#elif defined(BOOST_ENABLE_ASSERT_HANDLER)
65
Jeff Thompson2277ce52013-08-01 17:34:11 -070066 #include <ndnboost/current_function.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070067
68 namespace ndnboost
69 {
70 void assertion_failed_msg(char const * expr, char const * msg,
71 char const * function, char const * file, long line); // user defined
72 } // namespace ndnboost
73
74 #define BOOST_ASSERT_MSG(expr, msg) ((expr) \
75 ? ((void)0) \
76 : ::ndnboost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
77
78#else
79 #ifndef BOOST_ASSERT_HPP
80 #define BOOST_ASSERT_HPP
81 #include <cstdlib>
82 #include <iostream>
Jeff Thompson2277ce52013-08-01 17:34:11 -070083 #include <ndnboost/current_function.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070084
85 // IDE's like Visual Studio perform better if output goes to std::cout or
86 // some other stream, so allow user to configure output stream:
87 #ifndef BOOST_ASSERT_MSG_OSTREAM
88 # define BOOST_ASSERT_MSG_OSTREAM std::cerr
89 #endif
90
91 namespace ndnboost
92 {
93 namespace assertion
94 {
95 namespace detail
96 {
97 inline void assertion_failed_msg(char const * expr, char const * msg, char const * function,
98 char const * file, long line)
99 {
100 BOOST_ASSERT_MSG_OSTREAM
101 << "***** Internal Program Error - assertion (" << expr << ") failed in "
102 << function << ":\n"
103 << file << '(' << line << "): " << msg << std::endl;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700104 #ifdef UNDER_CE
105 // The Windows CE CRT library does not have abort() so use exit(-1) instead.
106 std::exit(-1);
107 #else
108 std::abort();
109 #endif
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700110 }
111 } // detail
112 } // assertion
113 } // detail
114 #endif
115
116 #define BOOST_ASSERT_MSG(expr, msg) ((expr) \
117 ? ((void)0) \
118 : ::ndnboost::assertion::detail::assertion_failed_msg(#expr, msg, \
119 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
120#endif
121
122//--------------------------------------------------------------------------------------//
123// BOOST_VERIFY //
124//--------------------------------------------------------------------------------------//
125
126#undef BOOST_VERIFY
127
128#if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
129
130# define BOOST_VERIFY(expr) ((void)(expr))
131
132#else
133
134# define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
135
136#endif