Debian Codegraph @

gnulib/m4/c-bool.m4

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