From 962a577b7685e0aa938b8241460c12484ae725c3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 9 Feb 2023 16:08:00 +0100 Subject: [PATCH] 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. --- ChangeLog | 2 ++ lib/limits.in.h | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) 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 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 */ -- 2.39.5