]> Savannah Git Hosting - gnulib.git/commitdiff
stdbool: Ensure that 'true' can be used in the preprocessor.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Sep 2022 16:47:22 +0000 (18:47 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 18 Sep 2022 17:11:17 +0000 (19:11 +0200)
* m4/c-bool.m4 (gl_C_BOOL): With Sun C++, redefine 'true' if it does not
evaluate to 1 in the preprocessor.

ChangeLog
m4/c-bool.m4

index 3ea944f7d249d804694806c297032331f1a10045..87c370bd043394fd09c93aa5a7e420718f5ed1db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2022-09-18  Bruno Haible  <bruno@clisp.org>
 
+       stdbool: Ensure that 'true' can be used in the preprocessor.
+       * m4/c-bool.m4 (gl_C_BOOL): With Sun C++, redefine 'true' if it does not
+       evaluate to 1 in the preprocessor.
+
        stdbool-c99: Ensure that 'true' can be used in the preprocessor.
        * lib/stdbool.in.h (true): Redefine if it does not evaluate to 1 in the
        preprocessor.
index db96ad10579238004b71ec2f1428444c2ff912f5..980de611b9ef23dd7276c3974f89e58bdb0e974a 100644 (file)
@@ -23,11 +23,21 @@ AC_DEFUN([gl_C_BOOL],
   fi
 
   dnl The "zz" puts this toward config.h's end, to avoid potential
-  dnl collisions with other definitions.  Check
-  dnl __bool_true_false_are_defined to avoid re-including <stdbool.h>.
+  dnl collisions with other definitions.
+  dnl In C++ mode 'bool', 'true', 'false' are keywords and thus we don't need
+  dnl <stdbool.h>.  But in C mode, we do.
+  dnl Check __bool_true_false_are_defined to avoid re-including <stdbool.h>.
+  dnl In Sun C++ 5.11 (Solaris Studio 12.2) and older, 'true' as a preprocessor
+  dnl expression evaluates to 0, not 1.  Fix this by overriding 'true'.  Note
+  dnl that the replacement has to be of type 'bool'.
   AH_VERBATIM([zzbool],
-[#if (!defined HAVE_C_BOOL && !defined __cplusplus \
-     && !defined __bool_true_false_are_defined)
- #include <stdbool.h>
+[#if !defined HAVE_C_BOOL
+# if !defined __cplusplus && !defined __bool_true_false_are_defined
+#  include <stdbool.h>
+# endif
+# if defined __SUNPRO_CC && true != 1
+#  undef true
+#  define true (!false)
+# endif
 #endif])
 ])