YSTest: cassert.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

cassert.h
浏览该文件的文档.
1 /*
2 © 2012-2016, 2018-2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_cassert_h_
29 #define YB_INC_ystdex_cassert_h_ 1
30
31 #include "../ydef.h"
32 #include <cstdio> // for std::FILE;
33
34 namespace ystdex
35 {
36
45 YB_NORETURN YB_API void
46 yassert(const char*, const char*, int, const char*) ynothrow;
47
48 #if YB_Use_YTrace
49
54 YB_API YB_ATTR_gnu_printf(6, 7) void
55 ytrace(std::FILE*, std::uint8_t, std::uint8_t, const char*, int, const char*,
56 ...) ynothrow;
57 #endif
58
59 } // namespace ystdex;
60
61 #endif // NOTE: Allow multiple for macro definitions.
62
63 #include <cassert>
64
65 #undef yconstraint
66 #undef yassume
67
68 // NOTE: Workaround for default warnings enabled by '-Wall'. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308.
69 // TODO: Reevaluate for future versions of GCC.
70 #if YB_IMPL_GNUCPP >= 60000
71 # pragma GCC diagnostic ignored "-Wnonnull-compare"
72 #endif
73
93 #ifdef NDEBUG
94 # define yassume(_expr) (YB_ASSUME(_expr), void())
95 #else
96 # define yassume(_expr) (assert(_expr), void())
97 #endif
98
110 #ifdef NDEBUG
111 # if YB_IMPL_CLANGPP >= 30401
112 # define yconstraint(_expr) \
113 ((YB_Diag_Push YB_Diag_Ignore(pointer-bool-conversion) YB_ASSUME(_expr) \
114 YB_Diag_Pop), void())
115 # else
116 # define yconstraint(_expr) (YB_ASSUME(_expr), void())
117 # endif
118 #else
119 # if YB_IMPL_CLANGPP >= 30401
120 # define yconstraint(_expr) \
121 ((YB_Diag_Push YB_Diag_Ignore(pointer-bool-conversion) _expr \
122 YB_Diag_Pop) ? void() \
123 : ystdex::yassert(#_expr, __FILE__, __LINE__, "Constraint violation."))
124 # else
125 # define yconstraint(_expr) \
126 ((_expr) ? void() : ystdex::yassert(#_expr, __FILE__, __LINE__, \
127 "Constraint violation."))
128 # endif
129 #endif
130
131
141 #ifdef NDEBUG
142 # define yverify(_expr) void()
143 #else
144 # define yverify(_expr) \
145 ((_expr) ? void() : ystdex::yassert(#_expr, __FILE__, __LINE__, \
146 "Verification failure."))
147 #endif
148
149
150
151 // NOTE: As %assert, this may be undefined and redefined.
152 #ifndef YAssert
153 # if YB_Use_YAssert
154 # define YAssert(_expr, _msg) \
155 ((_expr) ? void(0) : ystdex::yassert(#_expr, __FILE__, __LINE__, _msg))
156 # else
157 // XXX: This does not use %yassume to prevent %_expr being evaluated.
158 # define YAssert(_expr, _msg) assert(_expr)
159 # endif
160 #endif
161
162 // NOTE: As %assert, this may be undefined and redefined.
163 #ifndef YAssertNonnull
164 # define YAssertNonnull(_expr) YAssert(bool(_expr), "Null reference found.")
166 #endif
167
168 #ifndef YTrace
169
171
176 # if YB_Use_YTrace
177 # define YTrace(_stream, _lv, _t, _msg, ...) \
178 ystdex::ytrace(_stream, _lv, _t, __FILE__, __LINE__, _msg, __VA_ARGS__)
179 # else
180 # define YTrace(...)
181 # endif
182 #endif
183
184
YB_ATTR_gnu_printf
#define YB_ATTR_gnu_printf(...)
GNU 风格 printf 属性。
Definition: ydef.h:671
ystdex::ytrace
void ytrace(std::FILE *, std::uint8_t, std::uint8_t, const char *, int, const char *,...)
YCLib 调试跟踪函数。
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:877
std
Definition: optional.h:982
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:985
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::yassert
void yassert(const char *, const char *, int, const char *)
YBase 默认断言函数。
Definition: cassert.cpp:36
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199