YSTest: cassert.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

cassert.h
浏览该文件的文档.
1 /*
2 © 2012-2016 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>
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_GNUC >= 60000
71 # pragma GCC diagnostic ignored "-Wnonnull-compare"
72 #endif
73
85 #ifdef NDEBUG
86 # define yconstraint(_expr) YB_ASSUME(_expr)
87 #else
88 # define yconstraint(_expr) \
89 ((_expr) ? void(0) : ystdex::yassert(#_expr, __FILE__, __LINE__, \
90 "Constraint violation."))
91 #endif
92
102 #ifdef NDEBUG
103 # define yassume(_expr) YB_ASSUME(_expr)
104 #else
105 # define yassume(_expr) assert(_expr)
106 #endif
107
108
109 #ifndef YAssert
110 # if YB_Use_YAssert
111 # define YAssert(_expr, _msg) \
112 ((_expr) ? void(0) : ystdex::yassert(#_expr, __FILE__, __LINE__, _msg))
113 # else
114 # define YAssert(_expr, _msg) yassume(_expr)
115 # endif
116 #endif
117
118 #ifndef YAssertNonnull
119 # define YAssertNonnull(_expr) YAssert(bool(_expr), "Null reference found.")
121 #endif
122
123 #ifndef YTrace
124
126
131 # if YB_Use_YTrace
132 # define YTrace(_stream, _lv, _t, _msg, ...) \
133 ystdex::ytrace(_stream, _lv, _t, __FILE__, __LINE__, _msg, __VA_ARGS__)
134 # else
135 # define YTrace(...)
136 # endif
137 #endif
138
139
ystdex::yassert
void yassert(const char *, const char *, int, const char *)
YBase 默认断言函数。
Definition: cassert.cpp:36
ystdex::ytrace
void ytrace(std::FILE *, std::uint8_t, std::uint8_t, const char *, int, const char *,...)
YCLib 调试跟踪函数。
YB_ATTR_gnu_printf
#define YB_ATTR_gnu_printf(...)
GNU 风格 printf 属性。
Definition: ydef.h:398
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex
特性测试宏。
Definition: ydef.h:822
std
Definition: memory.hpp:1183
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:504
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:592