From 5c3f63123e9cbfd80eb4b010d6ab0939a5c8e099 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 9 Feb 2023 13:30:04 +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 | 8 ++++++++ doc/posix-headers/limits.texi | 3 +++ lib/limits.in.h | 15 +++++++++------ m4/limits-h.m4 | 3 ++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66b0c6f7aa..4f322a4670 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-02-09 Bruno Haible + + 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 Fix error in C++ mode on glibc systems (regression 2022-04-28). 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/lib/limits.in.h b/lib/limits.in.h index b77bf75c5f..03815ab783 100644 --- a/lib/limits.in.h +++ b/lib/limits.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright 2016-2022 Free Software Foundation, Inc. + Copyright 2016-2023 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -119,11 +119,14 @@ /* Macros specified by C2x. */ -#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 */ diff --git a/m4/limits-h.m4 b/m4/limits-h.m4 index 5d5a5bf584..4f8ce41098 100644 --- a/m4/limits-h.m4 +++ b/m4/limits-h.m4 @@ -1,6 +1,6 @@ dnl Check whether limits.h has needed features. -dnl Copyright 2016-2022 Free Software Foundation, Inc. +dnl Copyright 2016-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -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])]) -- 2.39.5