| 1 | # Check for stdbool.h that conforms to C99.
|
|---|
| 2 |
|
|---|
| 3 | dnl Copyright (C) 2002-2006, 2009-2021 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 | #serial 8
|
|---|
| 9 |
|
|---|
| 10 | # Prepare for substituting <stdbool.h> if it is not supported.
|
|---|
| 11 |
|
|---|
| 12 | AC_DEFUN([AM_STDBOOL_H],
|
|---|
| 13 | [
|
|---|
| 14 | AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
|
|---|
| 15 | AC_REQUIRE([AC_CANONICAL_HOST])
|
|---|
| 16 |
|
|---|
| 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
|
|---|
| 22 | case "$host_os" in
|
|---|
| 23 | solaris*)
|
|---|
| 24 | if test -z "$GCC"; then
|
|---|
| 25 | STDBOOL_H='stdbool.h'
|
|---|
| 26 | else
|
|---|
| 27 | STDBOOL_H=''
|
|---|
| 28 | fi
|
|---|
| 29 | ;;
|
|---|
| 30 | *)
|
|---|
| 31 | STDBOOL_H=''
|
|---|
| 32 | ;;
|
|---|
| 33 | esac
|
|---|
| 34 | else
|
|---|
| 35 | STDBOOL_H='stdbool.h'
|
|---|
| 36 | fi
|
|---|
| 37 | AC_SUBST([STDBOOL_H])
|
|---|
| 38 | AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
|
|---|
| 39 |
|
|---|
| 40 | if test "$ac_cv_type__Bool" = yes; then
|
|---|
| 41 | HAVE__BOOL=1
|
|---|
| 42 | else
|
|---|
| 43 | HAVE__BOOL=0
|
|---|
| 44 | fi
|
|---|
| 45 | AC_SUBST([HAVE__BOOL])
|
|---|
| 46 | ])
|
|---|
| 47 |
|
|---|
| 48 | # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
|
|---|
| 49 | AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
|
|---|
| 50 |
|
|---|
| 51 | # This version of the macro is needed in autoconf <= 2.68.
|
|---|
| 52 |
|
|---|
| 53 | AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
|
|---|
| 54 | [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
|
|---|
| 55 | [ac_cv_header_stdbool_h],
|
|---|
| 56 | [AC_COMPILE_IFELSE(
|
|---|
| 57 | [AC_LANG_PROGRAM(
|
|---|
| 58 | [[
|
|---|
| 59 | #include <stdbool.h>
|
|---|
| 60 |
|
|---|
| 61 | #ifdef __cplusplus
|
|---|
| 62 | typedef bool Bool;
|
|---|
| 63 | #else
|
|---|
| 64 | typedef _Bool Bool;
|
|---|
| 65 | #ifndef bool
|
|---|
| 66 | "error: bool is not defined"
|
|---|
| 67 | #endif
|
|---|
| 68 | #ifndef false
|
|---|
| 69 | "error: false is not defined"
|
|---|
| 70 | #endif
|
|---|
| 71 | #if false
|
|---|
| 72 | "error: false is not 0"
|
|---|
| 73 | #endif
|
|---|
| 74 | #ifndef true
|
|---|
| 75 | "error: true is not defined"
|
|---|
| 76 | #endif
|
|---|
| 77 | #if true != 1
|
|---|
| 78 | "error: true is not 1"
|
|---|
| 79 | #endif
|
|---|
| 80 | #endif
|
|---|
| 81 |
|
|---|
| 82 | #ifndef __bool_true_false_are_defined
|
|---|
| 83 | "error: __bool_true_false_are_defined is not defined"
|
|---|
| 84 | #endif
|
|---|
| 85 |
|
|---|
| 86 | struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
|
|---|
| 87 |
|
|---|
| 88 | char a[true == 1 ? 1 : -1];
|
|---|
| 89 | char b[false == 0 ? 1 : -1];
|
|---|
| 90 | char c[__bool_true_false_are_defined == 1 ? 1 : -1];
|
|---|
| 91 | char d[(bool) 0.5 == true ? 1 : -1];
|
|---|
| 92 | /* See body of main program for 'e'. */
|
|---|
| 93 | char f[(Bool) 0.0 == false ? 1 : -1];
|
|---|
| 94 | char g[true];
|
|---|
| 95 | char h[sizeof (Bool)];
|
|---|
| 96 | char i[sizeof s.t];
|
|---|
| 97 | enum { j = false, k = true, l = false * true, m = true * 256 };
|
|---|
| 98 | /* The following fails for
|
|---|
| 99 | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
|
|---|
| 100 | Bool n[m];
|
|---|
| 101 | char o[sizeof n == m * sizeof n[0] ? 1 : -1];
|
|---|
| 102 | char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
|
|---|
| 103 | /* Catch a bug in an HP-UX C compiler. See
|
|---|
| 104 | https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
|
|---|
| 105 | https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
|
|---|
| 106 | */
|
|---|
| 107 | Bool q = true;
|
|---|
| 108 | Bool *pq = &q;
|
|---|
| 109 | bool *qq = &q;
|
|---|
| 110 | ]],
|
|---|
| 111 | [[
|
|---|
| 112 | bool e = &s;
|
|---|
| 113 | *pq |= q; *pq |= ! q;
|
|---|
| 114 | *qq |= q; *qq |= ! q;
|
|---|
| 115 | /* Refer to every declared value, to avoid compiler optimizations. */
|
|---|
| 116 | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
|
|---|
| 117 | + !m + !n + !o + !p + !q + !pq + !qq);
|
|---|
| 118 | ]])],
|
|---|
| 119 | [ac_cv_header_stdbool_h=yes],
|
|---|
| 120 | [ac_cv_header_stdbool_h=no])])
|
|---|
| 121 | AC_CHECK_TYPES([_Bool])
|
|---|
| 122 | ])
|
|---|