stdbool.m4 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Check for stdbool.h that conforms to C99.
  2. dnl Copyright (C) 2002-2006, 2009-2021 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. #serial 8
  7. # Prepare for substituting <stdbool.h> if it is not supported.
  8. AC_DEFUN([AM_STDBOOL_H],
  9. [
  10. AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
  11. AC_REQUIRE([AC_CANONICAL_HOST])
  12. dnl On some platforms, <stdbool.h> does not exist or does not conform to C99.
  13. dnl On Solaris 10 with CC=cc CXX=CC, <stdbool.h> exists but is not usable
  14. dnl in C++ mode (and no <cstdbool> exists). In this case, we use our
  15. dnl replacement, also in C mode (for binary compatibility between C and C++).
  16. if test "$ac_cv_header_stdbool_h" = yes; then
  17. case "$host_os" in
  18. solaris*)
  19. if test -z "$GCC"; then
  20. STDBOOL_H='stdbool.h'
  21. else
  22. STDBOOL_H=''
  23. fi
  24. ;;
  25. *)
  26. STDBOOL_H=''
  27. ;;
  28. esac
  29. else
  30. STDBOOL_H='stdbool.h'
  31. fi
  32. AC_SUBST([STDBOOL_H])
  33. AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
  34. if test "$ac_cv_type__Bool" = yes; then
  35. HAVE__BOOL=1
  36. else
  37. HAVE__BOOL=0
  38. fi
  39. AC_SUBST([HAVE__BOOL])
  40. ])
  41. # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
  42. AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
  43. # This version of the macro is needed in autoconf <= 2.68.
  44. AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
  45. [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
  46. [ac_cv_header_stdbool_h],
  47. [AC_COMPILE_IFELSE(
  48. [AC_LANG_PROGRAM(
  49. [[
  50. #include <stdbool.h>
  51. #ifdef __cplusplus
  52. typedef bool Bool;
  53. #else
  54. typedef _Bool Bool;
  55. #ifndef bool
  56. "error: bool is not defined"
  57. #endif
  58. #ifndef false
  59. "error: false is not defined"
  60. #endif
  61. #if false
  62. "error: false is not 0"
  63. #endif
  64. #ifndef true
  65. "error: true is not defined"
  66. #endif
  67. #if true != 1
  68. "error: true is not 1"
  69. #endif
  70. #endif
  71. #ifndef __bool_true_false_are_defined
  72. "error: __bool_true_false_are_defined is not defined"
  73. #endif
  74. struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
  75. char a[true == 1 ? 1 : -1];
  76. char b[false == 0 ? 1 : -1];
  77. char c[__bool_true_false_are_defined == 1 ? 1 : -1];
  78. char d[(bool) 0.5 == true ? 1 : -1];
  79. /* See body of main program for 'e'. */
  80. char f[(Bool) 0.0 == false ? 1 : -1];
  81. char g[true];
  82. char h[sizeof (Bool)];
  83. char i[sizeof s.t];
  84. enum { j = false, k = true, l = false * true, m = true * 256 };
  85. /* The following fails for
  86. HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
  87. Bool n[m];
  88. char o[sizeof n == m * sizeof n[0] ? 1 : -1];
  89. char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
  90. /* Catch a bug in an HP-UX C compiler. See
  91. https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
  92. https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
  93. */
  94. Bool q = true;
  95. Bool *pq = &q;
  96. bool *qq = &q;
  97. ]],
  98. [[
  99. bool e = &s;
  100. *pq |= q; *pq |= ! q;
  101. *qq |= q; *qq |= ! q;
  102. /* Refer to every declared value, to avoid compiler optimizations. */
  103. return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
  104. + !m + !n + !o + !p + !q + !pq + !qq);
  105. ]])],
  106. [ac_cv_header_stdbool_h=yes],
  107. [ac_cv_header_stdbool_h=no])])
  108. AC_CHECK_TYPES([_Bool])
  109. ])