stdbool.m4 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Check for stdbool.h that conforms to C99.
  2. dnl Copyright (C) 2002-2006, 2009-2017 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 7
  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. # Define two additional variables used in the Makefile substitution.
  12. if test "$ac_cv_header_stdbool_h" = yes; then
  13. STDBOOL_H=''
  14. else
  15. STDBOOL_H='stdbool.h'
  16. fi
  17. AC_SUBST([STDBOOL_H])
  18. AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
  19. if test "$ac_cv_type__Bool" = yes; then
  20. HAVE__BOOL=1
  21. else
  22. HAVE__BOOL=0
  23. fi
  24. AC_SUBST([HAVE__BOOL])
  25. ])
  26. # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
  27. AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
  28. # This version of the macro is needed in autoconf <= 2.68.
  29. AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
  30. [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
  31. [ac_cv_header_stdbool_h],
  32. [AC_COMPILE_IFELSE(
  33. [AC_LANG_PROGRAM(
  34. [[
  35. #include <stdbool.h>
  36. #ifdef __cplusplus
  37. typedef bool Bool;
  38. #else
  39. typedef _Bool Bool;
  40. #ifndef bool
  41. "error: bool is not defined"
  42. #endif
  43. #ifndef false
  44. "error: false is not defined"
  45. #endif
  46. #if false
  47. "error: false is not 0"
  48. #endif
  49. #ifndef true
  50. "error: true is not defined"
  51. #endif
  52. #if true != 1
  53. "error: true is not 1"
  54. #endif
  55. #endif
  56. #ifndef __bool_true_false_are_defined
  57. "error: __bool_true_false_are_defined is not defined"
  58. #endif
  59. struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
  60. char a[true == 1 ? 1 : -1];
  61. char b[false == 0 ? 1 : -1];
  62. char c[__bool_true_false_are_defined == 1 ? 1 : -1];
  63. char d[(bool) 0.5 == true ? 1 : -1];
  64. /* See body of main program for 'e'. */
  65. char f[(Bool) 0.0 == false ? 1 : -1];
  66. char g[true];
  67. char h[sizeof (Bool)];
  68. char i[sizeof s.t];
  69. enum { j = false, k = true, l = false * true, m = true * 256 };
  70. /* The following fails for
  71. HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
  72. Bool n[m];
  73. char o[sizeof n == m * sizeof n[0] ? 1 : -1];
  74. char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
  75. /* Catch a bug in an HP-UX C compiler. See
  76. http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
  77. http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
  78. */
  79. Bool q = true;
  80. Bool *pq = &q;
  81. bool *qq = &q;
  82. ]],
  83. [[
  84. bool e = &s;
  85. *pq |= q; *pq |= ! q;
  86. *qq |= q; *qq |= ! q;
  87. /* Refer to every declared value, to avoid compiler optimizations. */
  88. return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
  89. + !m + !n + !o + !p + !q + !pq + !qq);
  90. ]])],
  91. [ac_cv_header_stdbool_h=yes],
  92. [ac_cv_header_stdbool_h=no])])
  93. AC_CHECK_TYPES([_Bool])
  94. ])