mirror of
https://github.com/Icinga/icinga2.git
synced 2025-11-23 15:20:28 +01:00
This is necessary to stop MSVC complaining that "not all paths return a value", because it is not able to infer that the expression `false ? 0 : non_returning_function()` never returns. In the process of debugging this I've also slightly simplified the other assert macros and abort function, so they don't need compiler specific preprocessor-paths anymore.
25 lines
658 B
C++
25 lines
658 B
C++
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
|
|
#ifndef DEBUG_H
|
|
#define DEBUG_H
|
|
|
|
#include "i2-base.hpp"
|
|
|
|
#ifndef I2_DEBUG
|
|
# define ASSERT(expr) ((void)0)
|
|
#else /* I2_DEBUG */
|
|
# define ASSERT(expr) ((expr) ? void(0) : icinga_assert_fail(#expr, __FILE__, __LINE__))
|
|
#endif /* I2_DEBUG */
|
|
|
|
#define VERIFY(expr) ((expr) ? void(0) : icinga_assert_fail(#expr, __FILE__, __LINE__))
|
|
|
|
#define ABORT(expr) icinga_assert_fail(#expr, __FILE__, __LINE__)
|
|
|
|
[[noreturn]] inline void icinga_assert_fail(const char *expr, const char *file, int line) noexcept(true)
|
|
{
|
|
fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
|
|
std::abort();
|
|
}
|
|
|
|
#endif /* DEBUG_H */
|