limits-h: Work around a clang 15 bug.
authorBruno Haible <bruno@clisp.org>
Thu, 9 Feb 2023 12:30:04 +0000 (13:30 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 10 Feb 2023 02:44:24 +0000 (03:44 +0100)
* m4/limits-h.m4 (gl_LIMITS_H): Test also for BOOL_MAX.
* lib/limits.in.h: Handle the case where BOOL_WIDTH is present and
BOOL_MAX is missing.
* doc/posix-headers/limits.texi: Mention the clang bug.

ChangeLog
doc/posix-headers/limits.texi
lib/limits.in.h
m4/limits-h.m4

index e4c1814a4d814462e843b4038d59b6112638e262..9aa4b2d53e20a3260d45ebf4788f3c3c043c1be2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-02-09  Bruno Haible  <bruno@clisp.org>
+
+       limits-h: Work around a clang 15 bug.
+       * m4/limits-h.m4 (gl_LIMITS_H): Test also for BOOL_MAX.
+       * lib/limits.in.h: Handle the case where BOOL_WIDTH is present and
+       BOOL_MAX is missing.
+       * doc/posix-headers/limits.texi: Mention the clang bug.
+
 2023-02-09  Bruno Haible  <bruno@clisp.org>
 
        Fix error in C++ mode on glibc systems (regression 2022-04-28).
index 22dc4239f7d54b1ccba3da021ba1720209d86679..09440cac8d66d3f8a7d92d93a05fb4c7dd768817 100644 (file)
@@ -21,6 +21,9 @@ glibc 2.24, NetBSD 9.0, many others.
 The macros @code{BOOL_MAX} and @code{BOOL_WIDTH} are not defined on
 some platforms:
 glibc 2.32, many others.
+@item
+The macro @code{BOOL_MAX} is not defined with some compilers:
+clang 15.0.6.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{gethostname}:
index eaeac472299f1ec1f24487e8f989295a46b6658c..a01b4c6a28042c2486dd4bb1f317f2aa16076ea0 100644 (file)
 
 /* Macros specified by C23.  */
 
-#if (! defined BOOL_WIDTH \
-     && (defined _GNU_SOURCE \
-         || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
-# define BOOL_MAX 1
-# define BOOL_WIDTH 1
+#if (defined _GNU_SOURCE \
+     || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__))
+# if ! defined BOOL_WIDTH
+#  define BOOL_WIDTH 1
+#  define BOOL_MAX 1
+# elif ! defined BOOL_MAX
+#  define BOOL_MAX ((((1U << (BOOL_WIDTH - 1)) - 1) << 1) + 1)
+# endif
 #endif
 
 #endif /* _@GUARD_PREFIX@_LIMITS_H */
index 5088fa16fd3b71101d4fb4da1a4db4d653710481..4f8ce41098a96a2eea7c80be38051c3e9c76e5ec 100644 (file)
@@ -23,6 +23,7 @@ AC_DEFUN_ONCE([gl_LIMITS_H],
             int wb = WORD_BIT;
             int ullw = ULLONG_WIDTH;
             int bw = BOOL_WIDTH;
+            int bm = BOOL_MAX;
           ]])],
        [gl_cv_header_limits_width=yes],
        [gl_cv_header_limits_width=no])])