FreeRDP
Loading...
Searching...
No Matches
assert-api.h
1
21#pragma once
22
23#include <stdlib.h>
24#include <assert.h>
25
26#include <winpr/config.h>
27#include <winpr/platform.h>
28
29#if defined(WITH_VERBOSE_WINPR_ASSERT) && (WITH_VERBOSE_WINPR_ASSERT != 0)
30#define winpr_internal_assert(cond, file, fkt, line) \
31 do \
32 { \
33 if (!(cond)) \
34 winpr_int_assert(#cond, (file), (fkt), (line)); \
35 } while (0)
36
37#else
38#define winpr_internal_assert(cond, file, fkt, line) assert(cond)
39#endif
40
41#ifdef __cplusplus
42extern "C"
43{
44#endif
45
46 /* this function meant only to be used by WINPR_ASSERT
47 * it needs to be exported as our assert implementation calls this for debug logging.
48 *
49 * also export when WITH_VERBOSE_WINPR_ASSERT is disabled as other software might compile with
50 * it enabled
51 */
52 WINPR_API WINPR_NORETURN(void winpr_int_assert(const char* condstr, const char* file,
53 const char* fkt, size_t line));
54
55#ifdef __cplusplus
56}
57#endif
58
59#define WINPR_ASSERT_AT(cond, file, fkt, line) \
60 do \
61 { \
62 WINPR_PRAGMA_DIAG_PUSH \
63 WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
64 WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
65 WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
66 WINPR_DO_COVERITY_PRAGMA( \
67 coverity compliance block deviate 'CONSTANT_EXPRESSION_RESULT' 'WINPR_ASSERT') \
68 WINPR_DO_COVERITY_PRAGMA(coverity compliance block deviate : 2 'NO_EFFECT' 'WINPR_ASSERT') \
69 \
70 winpr_internal_assert((cond), (file), (fkt), (line)); \
71 \
72 WINPR_DO_COVERITY_PRAGMA( \
73 coverity compliance end_block 'CONSTANT_EXPRESSION_RESULT' 'NO_EFFECT') \
74 WINPR_PRAGMA_DIAG_POP \
75 } while (0)
76#define WINPR_ASSERT(cond) WINPR_ASSERT_AT((cond), __FILE__, __func__, __LINE__)
77
78#ifdef __cplusplus
79extern "C"
80{
81#endif
82#if defined(__cplusplus) && (__cplusplus >= 201703L) // C++ 17
83#define WINPR_STATIC_ASSERT(cond) static_assert(cond)
84#elif defined(__cplusplus) && (__cplusplus >= 201103L) // C++ 11
85#define WINPR_STATIC_ASSERT(cond) static_assert(cond, #cond)
86#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) // C23
87#define WINPR_STATIC_ASSERT(cond) static_assert(cond)
88#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) // C11
89#define WINPR_STATIC_ASSERT(cond) _Static_assert(cond, #cond)
90#else
91WINPR_PRAGMA_WARNING("static-assert macro not supported on this platform")
92#define WINPR_STATIC_ASSERT(cond) assert(cond)
93#endif
94
95#ifdef __cplusplus
96}
97#endif