11#include <Sawyer/Sawyer.h>
13#include <boost/config.hpp>
14#include <boost/lexical_cast.hpp>
16#ifdef __clang_analyzer__
104void fail(
const char *mesg,
const char *expr,
const std::string ¬e,
105 const char *filename,
unsigned linenum,
const char *funcname);
109 const char *filename,
unsigned linenum,
const char *funcname);
124#define ASSERT_always_require(expr) ASSERT_always_require2(expr, "")
125#define ASSERT_always_forbid(expr) ASSERT_always_forbid2(expr, "")
126#define ASSERT_always_not_null(expr) ASSERT_always_not_null2(expr, "")
127#define ASSERT_always_not_reachable(note) \
128 Sawyer::Assert::fail("reached impossible state", NULL, boost::lexical_cast<std::string>(note), \
129 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
130#define ASSERT_always_not_implemented(note) \
131 Sawyer::Assert::fail("not implemented yet", NULL, boost::lexical_cast<std::string>(note), \
132 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
134#ifdef __clang_analyzer__
136 #define ASSERT_always_require2(expr, note) assert(expr)
137 #define ASSERT_always_forbid2(expr, note) assert(!(expr))
138 #define ASSERT_always_not_null2(expr, note) assert((expr) != nullptr)
139 #define ASSERT_always_this() assert(this != NULL)
141 #define ASSERT_always_require2(expr, note) \
143 static_cast<void>(0) : \
144 Sawyer::Assert::fail("assertion failed", "required: " #expr, boost::lexical_cast<std::string>(note), \
145 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
147 #define ASSERT_always_forbid2(expr, note) \
149 static_cast<void>(0) : \
150 Sawyer::Assert::fail("assertion failed", \
151 "forbidden: " #expr, boost::lexical_cast<std::string>(note), \
152 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
154 #define ASSERT_always_not_null2(expr, note) \
156 static_cast<void>(0) : \
157 Sawyer::Assert::fail("null pointer", \
158 #expr, boost::lexical_cast<std::string>(note), __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
160 #if defined(__GNUC__) && !defined(__clang__)
161 #define ROSE_ASSERT_DIAG_PUSH _Pragma("GCC diagnostic push")
162 #define ROSE_ASSERT_DIAG_POP _Pragma("GCC diagnostic pop")
163 #define ROSE_ASSERT_DIAG_IGNORED _Pragma("GCC diagnostic ignored \"-Wnonnull-compare\"")
164 #elif defined(__clang__)
165 #define ROSE_ASSERT_DIAG_PUSH _Pragma("GCC diagnostic push")
166 #define ROSE_ASSERT_DIAG_POP _Pragma("GCC diagnostic pop")
167 #define ROSE_ASSERT_DIAG_IGNORED _Pragma("GCC diagnostic ignored \"-Wtautological-undefined-compare\"")
169 #define ROSE_ASSERT_DIAG_PUSH
170 #define ROSE_ASSERT_DIAG_POP
171 #define ROSE_ASSERT_DIAG_IGNORED
174 #define ASSERT_suppress_nonnull_compare(expr) \
176 ROSE_ASSERT_DIAG_PUSH \
177 ROSE_ASSERT_DIAG_IGNORED \
179 ROSE_ASSERT_DIAG_POP \
182 #define ASSERT_always_this() \
183 ASSERT_suppress_nonnull_compare((this != NULL) ? \
184 static_cast<void>(0) : \
185 Sawyer::Assert::fail("null pointer", \
186 "this != NULL", boost::lexical_cast<std::string>(""), __FILE__, __LINE__, \
187 SAWYER_PRETTY_FUNCTION))
194#if defined(SAWYER_NDEBUG) && !defined(__clang_analyzer__)
196#define ASSERT_require(expr)
197#define ASSERT_require2(expr, note)
198#define ASSERT_forbid(expr)
199#define ASSERT_forbid2(expr, note)
200#define ASSERT_not_null(expr)
201#define ASSERT_not_null2(expr, note)
202#define ASSERT_not_reachable(note) ASSERT_always_not_reachable(note)
203#define ASSERT_not_implemented(note) ASSERT_always_not_implemented(note)
208#define ASSERT_require(expr) ASSERT_always_require(expr)
209#define ASSERT_require2(expr, note) ASSERT_always_require2(expr, note)
210#define ASSERT_forbid(expr) ASSERT_always_forbid(expr)
211#define ASSERT_forbid2(expr, note) ASSERT_always_forbid2(expr, note)
212#define ASSERT_not_null(expr) ASSERT_always_not_null(expr)
213#define ASSERT_not_null2(expr, note) ASSERT_always_not_null2(expr, note)
214#define ASSERT_not_reachable(note) ASSERT_always_not_reachable(note)
215#define ASSERT_not_implemented(note) ASSERT_always_not_implemented(note)
216#define ASSERT_this() ASSERT_always_this()
225 Sawyer::Assert::fail("not implemented yet", NULL, boost::lexical_cast<std::string>(note), \
226 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
229 Sawyer::Assert::fail("needs to be fixed", NULL, boost::lexical_cast<std::string>(note), \
230 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
void fail(const char *mesg, const char *expr, const std::string ¬e, const char *filename, unsigned linenum, const char *funcname)
Cause immediate failure.
void(* AssertFailureHandler)(const char *mesg, const char *expr, const std::string ¬e, const char *filename, unsigned linenum, const char *funcname)
Type for user-defined assertion failure handler.
AssertFailureHandler assertFailureHandler
Optional user callback to handle assertion failures.