-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssert.hpp
45 lines (42 loc) · 1.32 KB
/
Assert.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @file Assert.hpp
* @brief Assertion macros
*/
#ifndef INTERDEVCOPY_ASSERT_HPP_INCLUDE_
#define INTERDEVCOPY_ASSERT_HPP_INCLUDE_
#include <cstdio>
namespace interdevcopy {
namespace util {
[[noreturn]] void _assertion_failure(const char *, const char *, int);
[[noreturn]] void _bug(const char *, const char *, int);
}// namespace interdevcopy::util
}// namespace interdevcopy
/**
* @def INTERDEVCOPY_ASSERT(expr_)
* @brief a basic assertion macro
* @param expr_ an expression to test
*
* Prints an error message and terminates the program if expr is false.
*/
#define INTERDEVCOPY_ASSERT(expr_) \
do { if (!(expr_)) \
interdevcopy::util::_assertion_failure(#expr_, __FILE__, __LINE__); \
} while (0)
/**
* @def INTERDEVCOPY_ASSERT_ZERO(expr_)
* @brief an assertion macro to test the expression is zero.
* @param expr_ an expression to test
*
* Prints an error message and the (unexpected) value of expression,
* and terminates the program if expr is not zero.
*/
#define INTERDEVCOPY_ASSERT_ZERO(expr_) \
do { long val_ = (expr_); \
if (val_ != 0) { \
char msgstr_[sizeof(#expr_)+64]; \
std::snprintf(msgstr_, sizeof(msgstr_), "%s is not 0 (%ld)", \
#expr_, val_); \
interdevcopy::util::_assertion_failure(msgstr_, __FILE__, __LINE__); \
} \
} while (0)
#endif