]> Savannah Git Hosting - gnulib.git/commitdiff
stdbool: upgrade from C99 to C23
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 Sep 2022 16:41:31 +0000 (11:41 -0500)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 Sep 2022 16:45:05 +0000 (11:45 -0500)
Change the stdbool module so that it now emulates C23.
The module now assumes C99.  The old module (which assumes
C89 and emulates C99) is still available  as stdbool-c99,
but is deprecated.
* tests/test-stdbool.c [TEST_STDBOOL_H]: Do not include stdbool.h.
(WORKING_BOOL): Depend on HAVE_C_BOOL, not __STDC_VERSION__.
* m4/c-bool.m4, modules/c-bool, modules/c-bool-tests:
* tests/test-c-bool.c: New files.

ChangeLog
NEWS
doc/gnulib.texi
doc/posix-headers/stdbool.texi
m4/c-bool.m4 [new file with mode: 0644]
modules/stdbool
modules/stdbool-c99 [new file with mode: 0644]
modules/stdbool-c99-tests [new file with mode: 0644]
modules/stdbool-tests
tests/test-stdbool-c99.c [new file with mode: 0644]
tests/test-stdbool.c

index 928c1b667ed8425f15b2f791be965eee196d2aef..98ba79f6c17fe25acdb08d4a44d33c99f4126a49 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-09-10  Paul Eggert  <eggert@cs.ucla.edu>
+
+       stdbool: upgrade from C99 to C23
+       Change the stdbool module so that it now emulates C23.
+       The module now assumes C99.  The old module (which assumes
+       C89 and emulates C99) is still available  as stdbool-c99,
+       but is deprecated.
+       * tests/test-stdbool.c [TEST_C_BOOL]: Do not include stdbool.h.
+       * m4/c-bool.m4, modules/c-bool, modules/c-bool-tests:
+       * tests/test-c-bool.c: New files.
+
 2022-09-10  Bruno Haible  <bruno@clisp.org>
 
        string: Fix compilation error in C++ mode on AIX 7.2 with xlclang.
diff --git a/NEWS b/NEWS
index c3f810101dd7a2ee89c6bf4628f77b81992e49a4..840564703ae1105c3e5ba7094a5cc2af7ed547b9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -74,6 +74,10 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2022-09-10  stdbool         This module now assumes C99 and provides C23,
+                            instead of providing C99.  For the old behavior,
+                            use the already-deprecated stdbool-c99 module.
+
 2022-03-09  statat          This module is deprecated.  Use fstatat instead.
 
 2022-01-05  stack           This module now uses idx_t instead of size_t
index 0cc25f9e88997bb68d7ed6c4a4c6e27e1fc1422c..e9c2fd8fa6b1027ace540fdd695012a0dd52bb70 100644 (file)
@@ -74,6 +74,7 @@ Documentation License''.
 * Extending Gnulib::
 * Miscellaneous Notes::
 * POSIX Substitutes Library::       Building as a separate substitutes library.
+* Keyword Substitutes::             Replacing language keywords.
 * Header File Substitutes::         Overriding system headers.
 * Function Substitutes::            Replacing system functions.
 * Legacy Function Substitutes::     Replacing system functions.
@@ -857,6 +858,37 @@ source code, or when the program uses a mix between C and C++ sources
 (requiring separate builds of the @code{posixlib} for the C compiler and
 for the C++ compiler).
 
+@node Keyword Substitutes
+@chapter ISO C Keyword Substitutes
+
+This chapter describes which keywords specified by ISO C are
+substituted by Gnulib.
+
+@menu
+* bool::  @code{bool}, @code{false}, and @code{true}
+@end menu
+
+@node bool
+@section @code{bool}
+
+Gnulib module: stdbool
+
+Portability problems fixed by Gnulib:
+@itemize
+@item
+The keywords @code{bool}, @code{true}, and @code{false} are not available:
+gcc 12 and other compilers predating C23.
+@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@item
+On pre-C23 platforms, the keyword substitutes are macros.
+
+@item
+On pre-C23 platforms, the keyword substitutes assume C99 or later.
+@end itemize
+
 @node Header File Substitutes
 @chapter ISO C and POSIX Header File Substitutes
 
index 5b7ed0753fef2c63f2cf05d7c478c1273e0c244d..d7ba4068fc1136c4e4094dc6c4bde5d97afcbf46 100644 (file)
@@ -3,7 +3,12 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdbool.h.html}
 
-Gnulib module: stdbool
+Gnulib module: stdbool-c99
+
+The @code{stdbool-c99} module is present only for programs that
+formerly used the old @code{stdbool} module for C99 compatibility,
+and that for some reason cannot use the current @code{stdbool} module
+for C23 compatibility.
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/m4/c-bool.m4 b/m4/c-bool.m4
new file mode 100644 (file)
index 0000000..db96ad1
--- /dev/null
@@ -0,0 +1,33 @@
+# Check for bool that conforms to C2023.
+
+dnl Copyright 2022 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.
+
+AC_DEFUN([gl_C_BOOL],
+[
+  AC_CACHE_CHECK([for bool, true, false], [gl_cv_c_bool],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_SOURCE([[
+          #if true == false
+           #error "true == false"
+          #endif
+          extern bool b;
+          bool b = true == false;]])],
+       [gl_cv_c_bool=yes],
+       [gl_cv_c_bool=no])])
+  if test "$gl_cv_c_bool" = yes; then
+    AC_DEFINE([HAVE_C_BOOL], [1],
+      [Define to 1 if bool, true and false work as per C2023.])
+  fi
+
+  dnl The "zz" puts this toward config.h's end, to avoid potential
+  dnl collisions with other definitions.  Check
+  dnl __bool_true_false_are_defined to avoid re-including <stdbool.h>.
+  AH_VERBATIM([zzbool],
+[#if (!defined HAVE_C_BOOL && !defined __cplusplus \
+     && !defined __bool_true_false_are_defined)
+ #include <stdbool.h>
+#endif])
+])
index c33d036bb73847649fb5adb79d94e44e273c6af3..b5a52523d3fd91396dad4aa81f43eb23ce58e756 100644 (file)
@@ -1,39 +1,15 @@
 Description:
-An <stdbool.h> that nearly conforms to C99.
-(Nearly: casts to bool may not work.)
+A bool that is like C23.
 
 Files:
-lib/stdbool.in.h
-m4/stdbool.m4
-
-Depends-on:
-gen-header
+m4/c-bool.m4
 
 configure.ac:
-gl_STDBOOL_H
-gl_CONDITIONAL_HEADER([stdbool.h])
-AC_PROG_MKDIR_P
+gl_C_BOOL
 
 Makefile.am:
-BUILT_SOURCES += $(STDBOOL_H)
-
-# We need the following in order to create <stdbool.h> when the system
-# doesn't have one that works.
-if GL_GENERATE_STDBOOL_H
-stdbool.h: stdbool.in.h $(top_builddir)/config.status
-@NMD@  $(AM_V_GEN)$(MKDIR_P) '%reldir%'
-       $(gl_V_at)$(SED_HEADER_STDOUT) \
-         -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' \
-         $(srcdir)/stdbool.in.h > $@-t
-       $(AM_V_at)mv $@-t $@
-else
-stdbool.h: $(top_builddir)/config.status
-       rm -f $@
-endif
-MOSTLYCLEANFILES += stdbool.h stdbool.h-t
 
 Include:
-<stdbool.h>
 
 License:
 LGPLv2+
diff --git a/modules/stdbool-c99 b/modules/stdbool-c99
new file mode 100644 (file)
index 0000000..985ba78
--- /dev/null
@@ -0,0 +1,51 @@
+Description:
+A <stdbool.h> that nearly conforms to C99.
+(Nearly: casts to bool may not work.)
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.  It is present only for programs that
+formerly used the old stdbool module for C99 compatibility,
+and that for some reason cannot use the current stdbool module
+for C23 compatibility.
+
+Files:
+lib/stdbool.in.h
+m4/stdbool.m4
+
+Depends-on:
+gen-header
+
+configure.ac:
+gl_STDBOOL_H
+gl_CONDITIONAL_HEADER([stdbool.h])
+AC_PROG_MKDIR_P
+
+Makefile.am:
+BUILT_SOURCES += $(STDBOOL_H)
+
+# We need the following in order to create <stdbool.h> when the system
+# doesn't have one that works.
+if GL_GENERATE_STDBOOL_H
+stdbool.h: stdbool.in.h $(top_builddir)/config.status
+@NMD@  $(AM_V_GEN)$(MKDIR_P) '%reldir%'
+       $(gl_V_at)$(SED_HEADER_STDOUT) \
+         -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' \
+         $(srcdir)/stdbool.in.h > $@-t
+       $(AM_V_at)mv $@-t $@
+else
+stdbool.h: $(top_builddir)/config.status
+       rm -f $@
+endif
+MOSTLYCLEANFILES += stdbool.h stdbool.h-t
+
+Include:
+<stdbool.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/stdbool-c99-tests b/modules/stdbool-c99-tests
new file mode 100644 (file)
index 0000000..3ca0ddb
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-stdbool.c
+tests/test-stdbool-c99.c
+
+Depends-on:
+stdbool-c++-tests
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-stdbool-c99
+check_PROGRAMS += test-stdbool-c99
index 0f875fbeedd8753d64bdb460cbc9ff296149ad9b..6905dfbedc6776ff2df64250fe0d73ca7515d118 100644 (file)
@@ -2,7 +2,6 @@ Files:
 tests/test-stdbool.c
 
 Depends-on:
-stdbool-c++-tests
 
 configure.ac:
 
diff --git a/tests/test-stdbool-c99.c b/tests/test-stdbool-c99.c
new file mode 100644 (file)
index 0000000..350c4a0
--- /dev/null
@@ -0,0 +1,2 @@
+#define TEST_STDBOOL_H
+#include "test-stdbool.c"
index 329f5d5378f84d907482094feb6cc63df56ced6d..73c871e8693d57a2e41b6ce1e360d667319dd646 100644 (file)
@@ -1,4 +1,4 @@
-/* Test of <stdbool.h> substitute.
+/* Test bool.
    Copyright (C) 2002-2007, 2009-2022 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -33,7 +33,9 @@
 
 #include <config.h>
 
-#include <stdbool.h>
+#ifdef TEST_STDBOOL_H
+# include <stdbool.h>
+#endif
 
 #if false
  "error: false is not 0"
@@ -44,7 +46,7 @@
 
 /* Several tests cannot be guaranteed with gnulib's <stdbool.h>, at
    least, not for all compilers and compiler options.  */
-#if (202311 <= __STDC_VERSION__ || defined __cplusplus \
+#if (HAVE_C_BOOL || defined __cplusplus \
      || HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__)
 # define WORKING_BOOL 1
 #else