bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* limits-h: Work around a clang 15 bug
@ 2023-02-09 12:33 Bruno Haible
  2023-02-09 15:11 ` Bruno Haible
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2023-02-09 12:33 UTC (permalink / raw)
  To: bug-gnulib

When compiling a Gnulib testdir with clang15 with -std=gnu2x option,
I see this compilation error:

../../gltests/test-limits-h.c:113:22: error: use of undeclared identifier 'BOOL_MAX'
int bool_attrs[] = { BOOL_MAX, BOOL_WIDTH };
                     ^
../../gltests/test-limits-h.c:114:16: error: use of undeclared identifier 'BOOL_MAX'
static_assert (BOOL_MAX == (((1U << (BOOL_WIDTH - 1)) - 1) * 2) + 1);
               ^
2 errors generated.
make[4]: *** [Makefile:23558: test-limits-h.o] Error 1

The reason is that clang's <limits.h> defines BOOL_WIDTH but not BOOL_MAX.

This patch provides a workaround.


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.
	* doc/posix-headers/limits.texi: Mention the clang bug.

diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi
index 22dc4239f7..09440cac8d 100644
--- a/doc/posix-headers/limits.texi
+++ b/doc/posix-headers/limits.texi
@@ -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}:
diff --git a/m4/limits-h.m4 b/m4/limits-h.m4
index 5088fa16fd..4f8ce41098 100644
--- a/m4/limits-h.m4
+++ b/m4/limits-h.m4
@@ -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])])





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: limits-h: Work around a clang 15 bug
  2023-02-09 12:33 limits-h: Work around a clang 15 bug Bruno Haible
@ 2023-02-09 15:11 ` Bruno Haible
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2023-02-09 15:11 UTC (permalink / raw)
  To: bug-gnulib

I wrote:
> 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.
> 	* doc/posix-headers/limits.texi: Mention the clang bug.

Oops, that was not sufficient. This patch is needed as well:


diff --git a/ChangeLog b/ChangeLog
index fc3663eedc..f0d757837e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
 
 	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>
diff --git a/lib/limits.in.h b/lib/limits.in.h
index eaeac47229..a01b4c6a28 100644
--- a/lib/limits.in.h
+++ b/lib/limits.in.h
@@ -119,11 +119,14 @@
 
 /* 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 */





^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-09 18:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 12:33 limits-h: Work around a clang 15 bug Bruno Haible
2023-02-09 15:11 ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).