summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-09-28 01:06:10 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-09-28 01:09:01 -0700
commitf6fb2b9e1f94917601201f5d43c15e92e99b2a2f (patch)
treeca8ea61ece3c0f2aa56a7aeffcc52c41b9ce4dfd /m4
parenta9b29ee4a0ffa4878d67eaf518dbeed098844b9e (diff)
downloademacs-f6fb2b9e1f94917601201f5d43c15e92e99b2a2f.tar.gz
Port better to C23 bool+true+false keywords
C23 is adding the C++ keywords bool, true, and false; prefer them to <stdbool.h> if they are available. * admin/merge-gnulib (GNULIB_MODULES): Add stdbool, which emulates C23 on pre-C23 platforms. (AVOIDED_MODULES): Remove stdbool; Gnulib has renamed this module to stdbool-c99 and nobody uses it so it does not need to be avoided. * m4/c-bool.m4: New file, from Gnulib stdbool module. * lib-src/seccomp-filter.c, src/conf_post.h, src/dynlib.h: * src/emacs-module.c, src/nsterm.m, src/systhread.h: * test/src/emacs-module-resources/mod-test.c: Use the C23 style and use bool without including <stdbool.h>. The Gnulib stdbool module causes config.h to include stdbool.h on pre-C23 platforms. * src/emacs-module.h.in: Don’t include <stdbool.h> if C23 or later, or if it has already been included.
Diffstat (limited to 'm4')
-rw-r--r--m4/c-bool.m451
-rw-r--r--m4/gnulib-comp.m43
2 files changed, 54 insertions, 0 deletions
diff --git a/m4/c-bool.m4 b/m4/c-bool.m4
new file mode 100644
index 00000000000..bb109b77968
--- /dev/null
+++ b/m4/c-bool.m4
@@ -0,0 +1,51 @@
+# 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
+
+ AC_CHECK_HEADERS_ONCE([stdbool.h])
+
+ dnl The "zz" puts this toward config.h's end, to avoid potential
+ dnl collisions with other definitions.
+ dnl If 'bool', 'true' and 'false' do not work, arrange for them to work.
+ dnl In C, this means including <stdbool.h> if it is not already included.
+ dnl However, if the preprocessor mistakenly treats 'true' as 0,
+ dnl define it to a bool expression equal to 1; this is needed in
+ dnl Sun C++ 5.11 (Oracle Solaris Studio 12.2, 2010) and older.
+ AH_VERBATIM([zzbool],
+[#ifndef HAVE_C_BOOL
+# if !defined __cplusplus && !defined __bool_true_false_are_defined
+# if HAVE_STDBOOL_H
+# include <stdbool.h>
+# else
+# if defined __SUNPRO_C
+# error "<stdbool.h> is not usable with this configuration. To make it usable, add -D_STDC_C99= to $CC."
+# else
+# error "<stdbool.h> does not exist on this platform. Use gnulib module 'stdbool-c99' instead of gnulib module 'stdbool'."
+# endif
+# endif
+# endif
+# if !true
+# define true (!false)
+# endif
+#endif])
+])
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 6a5f3006781..f1ac4991324 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -172,6 +172,7 @@ AC_DEFUN([gl_EARLY],
# Code from module stat-time:
# Code from module std-gnu11:
# Code from module stdalign:
+ # Code from module stdbool:
# Code from module stdckdint:
# Code from module stddef:
# Code from module stdint:
@@ -490,6 +491,7 @@ AC_DEFUN([gl_INIT],
gl_STDALIGN_H
gl_CONDITIONAL_HEADER([stdalign.h])
AC_PROG_MKDIR_P
+ gl_C_BOOL
gl_STDDEF_H
gl_STDDEF_H_REQUIRE_DEFAULTS
gl_CONDITIONAL_HEADER([stddef.h])
@@ -1428,6 +1430,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/assert_h.m4
m4/builtin-expect.m4
m4/byteswap.m4
+ m4/c-bool.m4
m4/canonicalize.m4
m4/clock_time.m4
m4/copy-file-range.m4