diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | doc/gnulib.texi | 32 | ||||
-rw-r--r-- | doc/posix-headers/stdbool.texi | 7 | ||||
-rw-r--r-- | m4/c-bool.m4 | 33 | ||||
-rw-r--r-- | modules/stdbool | 30 | ||||
-rw-r--r-- | modules/stdbool-c99 | 51 | ||||
-rw-r--r-- | modules/stdbool-c99-tests | 12 | ||||
-rw-r--r-- | modules/stdbool-tests | 1 | ||||
-rw-r--r-- | tests/test-stdbool-c99.c | 2 | ||||
-rw-r--r-- | tests/test-stdbool.c | 8 |
11 files changed, 159 insertions, 32 deletions
@@ -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. @@ -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 diff --git a/doc/gnulib.texi b/doc/gnulib.texi index 0cc25f9e88..e9c2fd8fa6 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -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 diff --git a/doc/posix-headers/stdbool.texi b/doc/posix-headers/stdbool.texi index 5b7ed0753f..d7ba4068fc 100644 --- a/doc/posix-headers/stdbool.texi +++ b/doc/posix-headers/stdbool.texi @@ -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 index 0000000000..db96ad1057 --- /dev/null +++ b/m4/c-bool.m4 @@ -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]) +]) diff --git a/modules/stdbool b/modules/stdbool index c33d036bb7..b5a52523d3 100644 --- a/modules/stdbool +++ b/modules/stdbool @@ -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 index 0000000000..985ba78892 --- /dev/null +++ b/modules/stdbool-c99 @@ -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 index 0000000000..3ca0ddb217 --- /dev/null +++ b/modules/stdbool-c99-tests @@ -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 diff --git a/modules/stdbool-tests b/modules/stdbool-tests index 0f875fbeed..6905dfbedc 100644 --- a/modules/stdbool-tests +++ b/modules/stdbool-tests @@ -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 index 0000000000..350c4a05a9 --- /dev/null +++ b/tests/test-stdbool-c99.c @@ -0,0 +1,2 @@ +#define TEST_STDBOOL_H +#include "test-stdbool.c" diff --git a/tests/test-stdbool.c b/tests/test-stdbool.c index 329f5d5378..73c871e869 100644 --- a/tests/test-stdbool.c +++ b/tests/test-stdbool.c @@ -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 |