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.
+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.
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
* 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.
(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
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
--- /dev/null
+# 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])
+])
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+
--- /dev/null
+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
--- /dev/null
+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
tests/test-stdbool.c
Depends-on:
-stdbool-c++-tests
configure.ac:
--- /dev/null
+#define TEST_STDBOOL_H
+#include "test-stdbool.c"
-/* 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
#include <config.h>
-#include <stdbool.h>
+#ifdef TEST_STDBOOL_H
+# include <stdbool.h>
+#endif
#if false
"error: false is not 0"
/* 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