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)
133#define ASSERT_always_this()
135#ifdef __clang_analyzer__
137 #define ASSERT_always_require2(expr, note) assert(expr)
138 #define ASSERT_always_forbid2(expr, note) assert(!(expr))
139 #define ASSERT_always_not_null2(expr, note) assert((expr) != nullptr)
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))
165#if defined(SAWYER_NDEBUG) && !defined(__clang_analyzer__)
167#define ASSERT_require(expr)
168#define ASSERT_require2(expr, note)
169#define ASSERT_forbid(expr)
170#define ASSERT_forbid2(expr, note)
171#define ASSERT_not_null(expr)
172#define ASSERT_not_null2(expr, note)
173#define ASSERT_not_reachable(note) ASSERT_always_not_reachable(note)
174#define ASSERT_not_implemented(note) ASSERT_always_not_implemented(note)
179#define ASSERT_require(expr) ASSERT_always_require(expr)
180#define ASSERT_require2(expr, note) ASSERT_always_require2(expr, note)
181#define ASSERT_forbid(expr) ASSERT_always_forbid(expr)
182#define ASSERT_forbid2(expr, note) ASSERT_always_forbid2(expr, note)
183#define ASSERT_not_null(expr) ASSERT_always_not_null(expr)
184#define ASSERT_not_null2(expr, note) ASSERT_always_not_null2(expr, note)
185#define ASSERT_not_reachable(note) ASSERT_always_not_reachable(note)
186#define ASSERT_not_implemented(note) ASSERT_always_not_implemented(note)
196 Sawyer::Assert::fail("not implemented yet", NULL, boost::lexical_cast<std::string>(note), \
197 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
200 Sawyer::Assert::fail("needs to be fixed", NULL, boost::lexical_cast<std::string>(note), \
201 __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.