autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Port AC_CHECK_HEADER_STDBOOL to C23


From: Paul Eggert
Subject: [PATCH] Port AC_CHECK_HEADER_STDBOOL to C23
Date: Sat, 13 Aug 2022 19:41:33 -0700

Modernize the bool documentation a bit too.
* lib/autoconf/headers.m4 (AC_CHECK_HEADER_STDBOOL):
Allow C23 too.
---
 NEWS                    | 19 +++++-------
 doc/autoconf.texi       | 21 ++++++++++---
 lib/autoconf/headers.m4 | 69 ++++++++---------------------------------
 3 files changed, 37 insertions(+), 72 deletions(-)

diff --git a/NEWS b/NEWS
index 204f95f1..1e6a978b 100644
--- a/NEWS
+++ b/NEWS
@@ -45,18 +45,13 @@ GNU Autoconf NEWS - User visible changes.
   represent cache file timestamps, thus avoiding some problems where
   automake incorrectly decides not to regenerate stale caches.
 
-*** AC_HEADER_STDBOOL and AC_CHECK_HEADER_STDBOOL are less picky.
-
-  When compiling C++, a ‘stdbool.h’ that exists, but does nothing, is
-  acceptable no matter what version of the C++ standard is in use.
-
-  (ISO C++ 2011 says that ‘stdbool.h’ should exist for compatibility
-  with C, but should *not* define ‘bool’, ‘true’, or ‘false’ as
-  macros.  ISO C++ 1998 doesn’t mention ‘stdbool.h’ at all.  Some C++
-  compilers implement the 2011 rule in their C++98 mode as well.
-  ‘bool’, ‘true’, and ‘false’ have been built into the C++ language
-  since the beginning, so a ‘stdbool.h’ that exists but does nothing
-  should be fine for all reasonable C++ programs.)
+*** AC_HEADER_STDBOOL, AC_CHECK_HEADER_STDBOOL are obsolescent and less picky.
+
+  These macros are now obsolescent, as programs can simply include
+  stdbool.h unconditionally.  If you use these macros, they now accept
+  a stdbool.h that exists but does nothing, so long as ‘bool’, ‘true’,
+  and ‘false’ work anyway.  This is for compatibility with C 2023 and
+  with C++.
 
 * Noteworthy changes in release 2.71 (2021-01-28) [stable]
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 209840c2..06a16333 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6141,6 +6141,9 @@ Check whether @file{stdbool.h} exists and conforms to C99 
or later,
 and cache the result in the @code{ac_cv_header_stdbool_h} variable.
 If the type @code{_Bool} is defined, define @code{HAVE__BOOL} to 1.
 
+This macro is obsolescent, as all current C compilers have @file{stdbool.h},
+a header that is itself obsolescent as of C 2023.
+
 This macro is intended for use by Gnulib (@pxref{Gnulib}) and other
 packages that supply a substitute @file{stdbool.h} on platforms lacking
 a conforming one.  The @code{AC_HEADER_STDBOOL} macro is better for code
@@ -6303,8 +6306,18 @@ New programs need not use this macro.
 @caindex header_stdbool_h
 If @file{stdbool.h} exists and conforms to C99 or later, define
 @code{HAVE_STDBOOL_H} to 1; if the type @code{_Bool} is defined, define
-@code{HAVE__BOOL} to 1.  To fulfill the standard's requirements, your
-program could contain the following code:
+@code{HAVE__BOOL} to 1.
+
+This macro is obsolescent, as all current C compilers have
+@file{stdbool.h}, a header that is itself obsolescent as of C 2023.
+Nowadays programs that need @code{bool}, @code{true} and @code{false}
+can include @file{stdbool.h} unconditionally, without using
+@code{AC_HEADER_STDBOOL}, and if such a program needs to be portable
+only to C 2023 or later it need not even include @file{stdbool.h}.
+
+This macro was originally intended for programs that needed to be
+portable to C89.  These obsolete programs could use the following code,
+so long as they assigned only 0 or 1 to @code{bool} variables:
 
 @example
 @group
@@ -6326,8 +6339,8 @@ typedef bool _Bool;
 @end group
 @end example
 
-Alternatively you can use the @samp{stdbool} package of Gnulib
-(@pxref{Gnulib}).  It simplifies your code so that it can say just
+Alternatively if you still need portability to C89 you can use the
+@samp{stdbool} package of Gnulib (@pxref{Gnulib}).  It lets code say just
 @code{#include <stdbool.h>}, and it adds support for less-common
 platforms.
 
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 5cd1f4d5..caf36fa4 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -572,27 +572,27 @@ fi
 
 # AC_CHECK_HEADER_STDBOOL
 # -----------------
-# Check for stdbool.h that conforms to C99.
+# Check for stdbool.h that conforms to C99 or later.
 AN_IDENTIFIER([bool], [AC_CHECK_HEADER_STDBOOL])
 AN_IDENTIFIER([true], [AC_CHECK_HEADER_STDBOOL])
 AN_IDENTIFIER([false],[AC_CHECK_HEADER_STDBOOL])
 AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
   [AC_CHECK_TYPES([_Bool])
-   AC_CACHE_CHECK([for stdbool.h that conforms to C99],
+   AC_CACHE_CHECK([for stdbool.h that conforms to C99 or later],
      [ac_cv_header_stdbool_h],
      [AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
            [[#include <stdbool.h>
 
-             #ifndef __bool_true_false_are_defined
-               #error "__bool_true_false_are_defined is not defined"
-             #endif
-             char a[__bool_true_false_are_defined == 1 ? 1 : -1];
+             /* "true" and "false" should be usable in #if expressions and
+                integer constant expressions, and "bool" should be a valid
+                type name.
 
-             /* Regardless of whether this is C++ or "_Bool" is a
-                valid type name, "true" and "false" should be usable
-                in #if expressions and integer constant expressions,
-                and "bool" should be a valid type name.  */
+                Although C 1999 requires bool, true, and false to be macros,
+                C 2023 and C++ 2011 overrule that, so do not test for that.
+                Although C 1999 requires __bool_true_false_are_defined and
+                _Bool, C 2023 says they are obsolescent, so do not require
+                them.  */
 
              #if !true
                #error "'true' is not true"
@@ -626,64 +626,21 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
              char n[sizeof m == h * sizeof m[0] ? 1 : -1];
              char o[-1 - (bool) 0 < 0 ? 1 : -1];
              /* Catch a bug in an HP-UX C compiler.  See
-         https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
-         https://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
+                https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
+                https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
               */
              bool p = true;
              bool *pp = &p;
-
-             /* C 1999 specifies that bool, true, and false are to be
-                macros, but C++ 2011 overrules this.  The C++ committee
-                was codifying existing practice, so we allow them to
-                not be macros whenever __cplusplus is defined.  */
-             #ifndef __cplusplus
-              #ifndef bool
-               #error "bool is not defined"
-              #endif
-              #ifndef false
-               #error "false is not defined"
-              #endif
-              #ifndef true
-               #error "true is not defined"
-              #endif
-             #endif
-
-             /* If _Bool is available, repeat with it all the tests
-                above that used bool.  */
-             #ifdef HAVE__BOOL
-               struct sB { _Bool s: 1; _Bool t; } t;
-
-               char q[(_Bool) 0.5 == true ? 1 : -1];
-               char r[(_Bool) 0.0 == false ? 1 : -1];
-               char u[sizeof (_Bool) > 0 ? 1 : -1];
-               char v[sizeof t.t > 0 ? 1 : -1];
-
-               _Bool w[h];
-               char x[sizeof m == h * sizeof m[0] ? 1 : -1];
-               char y[-1 - (_Bool) 0 < 0 ? 1 : -1];
-               _Bool z = true;
-               _Bool *pz = &p;
-             #endif
            ]],
            [[
              bool ps = &s;
              *pp |= p;
              *pp |= ! p;
 
-             #ifdef HAVE__BOOL
-               _Bool pt = &t;
-               *pz |= z;
-               *pz |= ! z;
-             #endif
-
              /* Refer to every declared value, so they cannot be
                 discarded as unused.  */
              return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !j + !k
-                     + !l + !m + !n + !o + !p + !pp + !ps
-             #ifdef HAVE__BOOL
-                     + !q + !r + !u + !v + !w + !x + !y + !z + !pt
-             #endif
-                    );
+                     + !l + !m + !n + !o + !p + !pp + !ps);
            ]])],
         [ac_cv_header_stdbool_h=yes],
         [ac_cv_header_stdbool_h=no])])
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]