1 # Check for stdbool.h that conforms to C99.
3 dnl Copyright (C) 2002-2006, 2009-2022 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.
10 # Prepare for substituting <stdbool.h> if it is not supported.
12 AC_DEFUN([gl_STDBOOL_H],
14 AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
15 AC_REQUIRE([AC_CANONICAL_HOST])
17 dnl On some platforms, <stdbool.h> does not exist or does not conform to C99.
18 dnl On Solaris 10 with CC=cc CXX=CC, <stdbool.h> exists but is not usable
19 dnl in C++ mode (and no <cstdbool> exists). In this case, we use our
20 dnl replacement, also in C mode (for binary compatibility between C and C++).
21 if test "$ac_cv_header_stdbool_h" = yes; then
24 if test -z "$GCC"; then
25 GL_GENERATE_STDBOOL_H=true
27 GL_GENERATE_STDBOOL_H=false
31 GL_GENERATE_STDBOOL_H=false
35 GL_GENERATE_STDBOOL_H=true
38 if test "$ac_cv_type__Bool" = yes; then
43 AC_SUBST([HAVE__BOOL])
46 m4_version_prereq([2.72], [], [
48 AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
49 [AC_CHECK_TYPES([_Bool])
50 AC_CACHE_CHECK([for stdbool.h that conforms to C99 or later],
51 [ac_cv_header_stdbool_h],
54 [[#include <stdbool.h>
56 /* "true" and "false" should be usable in #if expressions and
57 integer constant expressions, and "bool" should be a valid
60 Although C 1999 requires bool, true, and false to be macros,
61 C 2023 and C++ 2011 overrule that, so do not test for that.
62 Although C 1999 requires __bool_true_false_are_defined and
63 _Bool, C 2023 says they are obsolescent, so do not require
67 #error "'true' is not true"
70 #error "'true' is not equal to 1"
72 char b[true == 1 ? 1 : -1];
76 #error "'false' is not false"
79 #error "'false' is not equal to 0"
81 char d[false == 0 ? 1 : -1];
83 enum { e = false, f = true, g = false * true, h = true * 256 };
85 char i[(bool) 0.5 == true ? 1 : -1];
86 char j[(bool) 0.0 == false ? 1 : -1];
87 char k[sizeof (bool) > 0 ? 1 : -1];
89 struct sb { bool s: 1; bool t; } s;
90 char l[sizeof s.t > 0 ? 1 : -1];
92 /* The following fails for
93 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
95 char n[sizeof m == h * sizeof m[0] ? 1 : -1];
96 char o[-1 - (bool) 0 < 0 ? 1 : -1];
97 /* Catch a bug in an HP-UX C compiler. See
98 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
99 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
109 /* Refer to every declared value, so they cannot be
110 discarded as unused. */
111 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !j + !k
112 + !l + !m + !n + !o + !p + !pp + !ps);
114 [ac_cv_header_stdbool_h=yes],
115 [ac_cv_header_stdbool_h=no])])
116 ])# AC_CHECK_HEADER_STDBOOL
118 ]) # m4_version_prereq 2.72