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

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

commit acc26514743e49d540496daf4293ad19e09a7e2b
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Oct 28 17:26:36 2026 +0100

    include/stdbool.h: Do not define bool, true and false in C23.
    
    In C23 bool, true and false are keywords, and the <stdbool.h> of GCC
    and Clang defines only __bool_true_false_are_defined.  NuttX's
    <stdbool.h> still defined bool as a macro (_Bool or uint8_t), and
    several public headers include it (<pthread.h>, <sched.h>,
    <sys/poll.h>, <syslog.h>).  A C23 program then sees a macro named bool
    that other C libraries do not have, and a program that checks
    "#ifdef bool" stops with an #error.
    
    Define the three macros only if the compiler does not have the
    keywords.  GCC 13 and later and Clang 15 and later have them also in
    their C2X mode, where __STDC_VERSION__ is 202000L.  Older GCC and Clang
    versions in that mode, and other compilers below the C23 value 202311L,
    keep the macros.  The type does not change: the C23 keyword bool has
    the size of _Bool.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 include/stdbool.h | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/include/stdbool.h b/include/stdbool.h
index 847f20068fd..8bdf8e3e563 100644
--- a/include/stdbool.h
+++ b/include/stdbool.h
@@ -70,14 +70,24 @@
  */
 
 #  ifndef __cplusplus
-#    ifdef CONFIG_C99_BOOL
-#      define bool _Bool
-#    else
-#      define bool uint8_t
-#    endif
 
-#    define true  1
-#    define false 0
+/* bool, true and false are keywords in C23, and in the C2X mode of GCC 13
+ * and Clang 15 or later.  Then define only __bool_true_false_are_defined.
+ */
+
+#    if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L && \
+        (__STDC_VERSION__ <= 201710L || \
+         (!defined(__clang__) && (!defined(__GNUC__) || __GNUC__ < 13)) || \
+         (defined(__clang__) && __clang_major__ < 15)))
+#      ifdef CONFIG_C99_BOOL
+#        define bool _Bool
+#      else
+#        define bool uint8_t
+#      endif
+
+#      define true  1
+#      define false 0
+#    endif
 
 #    define __bool_true_false_are_defined 1
 #  else

Reply via email to