21 #ifndef WINPR_ASSERT_H
22 #define WINPR_ASSERT_H
27 #include <winpr/winpr.h>
28 #include <winpr/wtypes.h>
29 #include <winpr/wlog.h>
30 #include <winpr/debug.h>
32 #if defined(WITH_VERBOSE_WINPR_ASSERT) && (WITH_VERBOSE_WINPR_ASSERT != 0)
33 #define winpr_internal_assert(cond, file, fkt, line) \
37 winpr_int_assert(#cond, (file), (fkt), (line)); \
45 static INLINE WINPR_NORETURN(
void winpr_int_assert(
const char* condstr,
const char* file,
46 const char* fkt,
size_t line))
48 wLog* _log_cached_ptr = WLog_Get(
"com.freerdp.winpr.assert");
49 WLog_Print(_log_cached_ptr, WLOG_FATAL,
"%s [%s:%s:%" PRIuz
"]", condstr, file, fkt, line);
50 winpr_log_backtrace_ex(_log_cached_ptr, WLOG_FATAL, 20);
59 #define winpr_internal_assert(cond, file, fkt, line) assert(cond)
62 #define WINPR_ASSERT_AT(cond, file, fkt, line) \
65 WINPR_PRAGMA_DIAG_PUSH \
66 WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
67 WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
68 WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
69 WINPR_DO_COVERITY_PRAGMA(coverity compliance block \(deviate "CONSTANT_EXPRESSION_RESULT" \
71 \(deviate "NO_EFFECT" \
74 winpr_internal_assert((cond), (file), (fkt), (line)); \
76 WINPR_DO_COVERITY_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \
78 WINPR_PRAGMA_DIAG_POP \
80 #define WINPR_ASSERT(cond) WINPR_ASSERT_AT((cond), __FILE__, __func__, __LINE__)
86 #if defined(__cplusplus) && (__cplusplus >= 201703L)
87 #define WINPR_STATIC_ASSERT(cond) static_assert(cond)
88 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
89 #define WINPR_STATIC_ASSERT(cond) static_assert(cond, #cond)
90 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
91 #define WINPR_STATIC_ASSERT(cond) static_assert(cond)
92 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
93 #define WINPR_STATIC_ASSERT(cond) _Static_assert(cond, #cond)
95 WINPR_PRAGMA_WARNING(
"static-assert macro not supported on this platform")
96 #define WINPR_STATIC_ASSERT(cond) assert(cond)