With clang 17 and CC="clang -std=gnu2x", I see this compilation error:
../../gltests/test-limits-h.c:118:16: error: static assertion failed due to requirement '1 == (((1U << (8 - 1)) - 1) * 2) + 1' 118 | static_assert (BOOL_MAX == (((1U << (BOOL_WIDTH - 1)) - 1) * 2) + 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/limits.h:186:20: note: expanded from macro 'BOOL_MAX' 186 | # define BOOL_MAX 1 | ^ 1 error generated. make[3]: *** [Makefile:3853: test-limits-h.o] Error 1 The cause are the values of BOOL_WIDTH and BOOL_MAX. This program ================================================================================ #include <limits.h> #include <stdint.h> #include <stdio.h> int main () { printf ("BOOL_WIDTH = %d, BOOL_MAX = %d\n", BOOL_WIDTH, BOOL_MAX); } ================================================================================ prints BOOL_WIDTH = 1, BOOL_MAX = 1 with CC="gcc -std=gnu2x", but BOOL_WIDTH = 8, BOOL_MAX = 1 with CC="clang -std=gnu2x" (for all clang version 14 ... 17). Apparently I had misinterpreted the meaning of BOOL_WIDTH. (Cf. ISO C 23 ยง E.(3)). This patch fixes the compilation error. 2024-02-12 Bruno Haible <br...@clisp.org> limits-h: Fix BOOL_MAX value. * lib/limits.in.h (BOOL_MAX): Define to 1, not to 2^BOOL_WIDTH-1. * tests/test-limits-h.c (main): Change expected value of BOOL_MAX. diff --git a/lib/limits.in.h b/lib/limits.in.h index 236fc58e52..c65eb4c1cf 100644 --- a/lib/limits.in.h +++ b/lib/limits.in.h @@ -130,7 +130,7 @@ # define BOOL_WIDTH 1 # define BOOL_MAX 1 # elif ! defined BOOL_MAX -# define BOOL_MAX ((((1U << (BOOL_WIDTH - 1)) - 1) << 1) + 1) +# define BOOL_MAX 1 # endif #endif diff --git a/tests/test-limits-h.c b/tests/test-limits-h.c index 817e239c6e..6f574c88a0 100644 --- a/tests/test-limits-h.c +++ b/tests/test-limits-h.c @@ -115,7 +115,7 @@ verify_width (ULLONG_WIDTH, 0, ULLONG_MAX); /* Macros specified by C23. */ int bool_attrs[] = { BOOL_MAX, BOOL_WIDTH }; -static_assert (BOOL_MAX == (((1U << (BOOL_WIDTH - 1)) - 1) * 2) + 1); +static_assert (BOOL_MAX == 1); static_assert (0 < MB_LEN_MAX);