This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 23aba6c2a1edf98fc6f408bbc8da690e52c939f7
Author: yinshengkai <[email protected]>
AuthorDate: Wed Oct 18 22:24:21 2023 +0800

    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 <[email protected]>
---
 include/assert.h | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/include/assert.h b/include/assert.h
index 45d6e4d323..89d550a600 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -77,20 +77,10 @@
                                            __ASSERT_LINE__, msg, regs)
 
 #define __ASSERT__(f, file, line, _f) \
-  do                                  \
-    {                                 \
-      if (predict_false(!(f)))        \
-        __assert(file, line, _f);     \
-    }                                 \
-  while (0)
+  (predict_false(!(f))) ? __assert(file, line, _f) : ((void)0)
 
 #define __VERIFY__(f, file, line, _f) \
-  do                                  \
-    {                                 \
-      if (predict_false((f) < 0))     \
-        __assert(file, line, _f);     \
-    }                                 \
-  while (0)
+  (predict_false((f) < 0)) ? __assert(file, line, _f) : ((void)0)
 
 #ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION
 #  define _ASSERT(f,file,line) __ASSERT__(f, file, line, #f)

Reply via email to