From e8d4bea2f7b864f8f09db65e797d7b6ddb6039c0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 8 Sep 2022 23:46:23 -0500 Subject: [PATCH 1/2] c-bool: new module * 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. --- ChangeLog | 5 +++++ MODULES.html.sh | 1 + doc/gnulib.texi | 34 ++++++++++++++++++++++++++++++++++ m4/c-bool.m4 | 29 +++++++++++++++++++++++++++++ modules/c-bool | 18 ++++++++++++++++++ modules/c-bool-tests | 11 +++++++++++ tests/test-c-bool.c | 2 ++ tests/test-stdbool.c | 6 ++++-- 8 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 m4/c-bool.m4 create mode 100644 modules/c-bool create mode 100644 modules/c-bool-tests create mode 100644 tests/test-c-bool.c diff --git a/ChangeLog b/ChangeLog index 99b476be6e..80fb38c240 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2022-09-08 Paul Eggert + c-bool: new module + * 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. + stdbool-tests: match stdbool * tests/test-stdbool.c: Omit test for __bool_true_false_are_defined since AC_CHECK_HEADER_STDBOOL no diff --git a/MODULES.html.sh b/MODULES.html.sh index d48912b13e..4f6af683e2 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2383,6 +2383,7 @@ func_all_modules () func_echo "$element" func_begin_table + func_module c-bool func_module stdckdint func_end_table diff --git a/doc/gnulib.texi b/doc/gnulib.texi index 0cc25f9e88..16ca2690d3 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,39 @@ 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:: +@end menu + +@node bool +@section @code{bool} + +Gnulib module: c-bool + +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. +If your code needs to be portable to pre-C99 platforms, +it needs to also use the @code{stdbool} module. +@end itemize + @node Header File Substitutes @chapter ISO C and POSIX Header File Substitutes diff --git a/m4/c-bool.m4 b/m4/c-bool.m4 new file mode 100644 index 0000000000..9c47f58de4 --- /dev/null +++ b/m4/c-bool.m4 @@ -0,0 +1,29 @@ +# 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_DEFINES_PROVIDED[ + #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 + AH_VERBATIM([bool], +[#ifndef HAVE_C_BOOL + #include +#endif]) +]) diff --git a/modules/c-bool b/modules/c-bool new file mode 100644 index 0000000000..b5a52523d3 --- /dev/null +++ b/modules/c-bool @@ -0,0 +1,18 @@ +Description: +A bool that is like C23. + +Files: +m4/c-bool.m4 + +configure.ac: +gl_C_BOOL + +Makefile.am: + +Include: + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-bool-tests b/modules/c-bool-tests new file mode 100644 index 0000000000..671b6afb93 --- /dev/null +++ b/modules/c-bool-tests @@ -0,0 +1,11 @@ +Files: +tests/test-c-bool.c +tests/test-stdbool.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-c-bool +check_PROGRAMS += test-c-bool diff --git a/tests/test-c-bool.c b/tests/test-c-bool.c new file mode 100644 index 0000000000..df9436e4b6 --- /dev/null +++ b/tests/test-c-bool.c @@ -0,0 +1,2 @@ +#define TEST_C_BOOL +#include "test-stdbool.c" diff --git a/tests/test-stdbool.c b/tests/test-stdbool.c index 329f5d5378..98588329f3 100644 --- a/tests/test-stdbool.c +++ b/tests/test-stdbool.c @@ -1,4 +1,4 @@ -/* Test of 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 -#include +#ifndef TEST_C_BOOL +# include +#endif #if false "error: false is not 0" -- 2.37.2