mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
assert: change the do-while of assert to a conditional expression
According to the standard definition, assert should return a void expression https://pubs.opengroup.org/onlinepubs/007904875/basedefs/assert.h.html This patch involves two changes: If you define the NDEBUG macro, assert does not use any parameters and directly returns a void expression. assert should return a void expression and cannot use do-while statements. If the following code , a compilation error will occur. Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
+3
-13
@@ -79,20 +79,10 @@
|
|||||||
__ASSERT_LINE__, msg, regs)
|
__ASSERT_LINE__, msg, regs)
|
||||||
|
|
||||||
#define __ASSERT__(f, file, line, _f) \
|
#define __ASSERT__(f, file, line, _f) \
|
||||||
do \
|
(predict_false(!(f))) ? __assert(file, line, _f) : ((void)0)
|
||||||
{ \
|
|
||||||
if (predict_false(!(f))) \
|
|
||||||
__assert(file, line, _f); \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
#define __VERIFY__(f, file, line, _f) \
|
#define __VERIFY__(f, file, line, _f) \
|
||||||
do \
|
(predict_false((f) < 0)) ? __assert(file, line, _f) : ((void)0)
|
||||||
{ \
|
|
||||||
if (predict_false((f) < 0)) \
|
|
||||||
__assert(file, line, _f); \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION
|
#ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION
|
||||||
# define _ASSERT(f,file,line) __ASSERT__(f, file, line, #f)
|
# define _ASSERT(f,file,line) __ASSERT__(f, file, line, #f)
|
||||||
@@ -150,7 +140,7 @@
|
|||||||
# define static_assert _Static_assert
|
# define static_assert _Static_assert
|
||||||
# else
|
# else
|
||||||
# define static_assert(cond, msg) \
|
# define static_assert(cond, msg) \
|
||||||
extern int (*__static_assert_function (void)) \
|
extern int (*__static_assert_function(void)) \
|
||||||
[!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
|
[!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user