| 1 |
# c-bool.m4 |
| 2 |
# serial 3 |
| 3 |
dnl Copyright 2022-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
# Check for bool that conforms to C2023. |
| 10 |
|
| 11 |
AC_DEFUN([gl_C_BOOL], |
| 12 |
[ |
| 13 |
AC_CACHE_CHECK([for bool, true, false], [gl_cv_c_bool], |
| 14 |
[AC_COMPILE_IFELSE( |
| 15 |
[AC_LANG_SOURCE([[ |
| 16 |
#if true == false |
| 17 |
#error "true == false" |
| 18 |
#endif |
| 19 |
extern bool b; |
| 20 |
bool b = true == false;]])], |
| 21 |
[gl_cv_c_bool=yes], |
| 22 |
[gl_cv_c_bool=no])]) |
| 23 |
if test "$gl_cv_c_bool" = yes; then |
| 24 |
AC_DEFINE([HAVE_C_BOOL], [1], |
| 25 |
[Define to 1 if bool, true and false work as per C2023.]) |
| 26 |
fi |
| 27 |
|
| 28 |
AC_CHECK_HEADERS_ONCE([stdbool.h]) |
| 29 |
|
| 30 |
dnl The "zz" puts this toward config.h's end, to avoid potential |
| 31 |
dnl collisions with other definitions. |
| 32 |
dnl If 'bool', 'true' and 'false' do not work, arrange for them to work. |
| 33 |
dnl Hardcode the known configuration results for GCC and clang, so that |
| 34 |
dnl a configuration made with the C compiler works also with the C++ compiler |
| 35 |
dnl and vice versa. |
| 36 |
dnl The seemingly redundant parentheses are necessary for MSVC 14. |
| 37 |
dnl "Arrange for them to work", in C, means including <stdbool.h> if it is |
| 38 |
dnl not already included. |
| 39 |
dnl However, if the preprocessor mistakenly treats 'true' as 0, |
| 40 |
dnl define it to a bool expression equal to 1; this is needed in |
| 41 |
dnl Sun C++ 5.11 (Oracle Solaris Studio 12.2, 2010) and older. |
| 42 |
AH_VERBATIM([zzbool], |
| 43 |
[#if !(defined __cplusplus \ |
| 44 |
? 1 \ |
| 45 |
: (defined __clang__ \ |
| 46 |
? __STDC_VERSION__ >= 202000L && __clang_major__ >= 15 \ |
| 47 |
: (defined __GNUC__ \ |
| 48 |
? __STDC_VERSION__ >= 202000L && __GNUC__ >= 13 \ |
| 49 |
: defined HAVE_C_BOOL))) |
| 50 |
# if !defined __cplusplus && !defined __bool_true_false_are_defined |
| 51 |
# if HAVE_STDBOOL_H |
| 52 |
# include <stdbool.h> |
| 53 |
# else |
| 54 |
# if defined __SUNPRO_C |
| 55 |
# error "<stdbool.h> is not usable with this configuration. To make it usable, add -D_STDC_C99= to $CC." |
| 56 |
# else |
| 57 |
# error "<stdbool.h> does not exist on this platform. Use gnulib module 'stdbool-c99' instead of gnulib module 'stdbool'." |
| 58 |
# endif |
| 59 |
# endif |
| 60 |
# endif |
| 61 |
# if !true |
| 62 |
# define true (!false) |
| 63 |
# endif |
| 64 |
#endif]) |
| 65 |
]) |