version 1.1.1.1, 2012/02/21 22:57:49
|
version 1.1.1.3, 2021/03/17 13:38:46
|
Line 1
|
Line 1
|
# Check for stdbool.h that conforms to C99. |
# Check for stdbool.h that conforms to C99. |
|
|
dnl Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc. | dnl Copyright (C) 2002-2006, 2009-2019 Free Software Foundation, Inc. |
dnl This file is free software; the Free Software Foundation |
dnl This file is free software; the Free Software Foundation |
dnl gives unlimited permission to copy and/or distribute it, |
dnl gives unlimited permission to copy and/or distribute it, |
dnl with or without modifications, as long as this notice is preserved. |
dnl with or without modifications, as long as this notice is preserved. |
|
|
|
#serial 7 |
|
|
# Prepare for substituting <stdbool.h> if it is not supported. |
# Prepare for substituting <stdbool.h> if it is not supported. |
|
|
AC_DEFUN([AM_STDBOOL_H], |
AC_DEFUN([AM_STDBOOL_H], |
[ |
[ |
AC_REQUIRE([AC_HEADER_STDBOOL]) | AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) |
|
|
# Define two additional variables used in the Makefile substitution. |
# Define two additional variables used in the Makefile substitution. |
|
|
Line 19 AC_DEFUN([AM_STDBOOL_H],
|
Line 21 AC_DEFUN([AM_STDBOOL_H],
|
STDBOOL_H='stdbool.h' |
STDBOOL_H='stdbool.h' |
fi |
fi |
AC_SUBST([STDBOOL_H]) |
AC_SUBST([STDBOOL_H]) |
|
AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"]) |
|
|
if test "$ac_cv_type__Bool" = yes; then |
if test "$ac_cv_type__Bool" = yes; then |
HAVE__BOOL=1 |
HAVE__BOOL=1 |
Line 31 AC_DEFUN([AM_STDBOOL_H],
|
Line 34 AC_DEFUN([AM_STDBOOL_H],
|
# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. |
# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. |
AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) |
AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) |
|
|
# This macro is only needed in autoconf <= 2.59. Newer versions of autoconf | # This version of the macro is needed in autoconf <= 2.68. |
# have this macro built-in. | |
|
|
AC_DEFUN([AC_HEADER_STDBOOL], | AC_DEFUN([AC_CHECK_HEADER_STDBOOL], |
[AC_CACHE_CHECK([for stdbool.h that conforms to C99], |
[AC_CACHE_CHECK([for stdbool.h that conforms to C99], |
[ac_cv_header_stdbool_h], |
[ac_cv_header_stdbool_h], |
[AC_TRY_COMPILE( | [AC_COMPILE_IFELSE( |
[ | [AC_LANG_PROGRAM( |
#include <stdbool.h> | [[ |
#ifndef bool | #include <stdbool.h> |
"error: bool is not defined" | |
#endif | |
#ifndef false | |
"error: false is not defined" | |
#endif | |
#if false | |
"error: false is not 0" | |
#endif | |
#ifndef true | |
"error: true is not defined" | |
#endif | |
#if true != 1 | |
"error: true is not 1" | |
#endif | |
#ifndef __bool_true_false_are_defined | |
"error: __bool_true_false_are_defined is not defined" | |
#endif | |
|
|
struct s { _Bool s: 1; _Bool t; } s; | #ifdef __cplusplus |
| typedef bool Bool; |
| #else |
| typedef _Bool Bool; |
| #ifndef bool |
| "error: bool is not defined" |
| #endif |
| #ifndef false |
| "error: false is not defined" |
| #endif |
| #if false |
| "error: false is not 0" |
| #endif |
| #ifndef true |
| "error: true is not defined" |
| #endif |
| #if true != 1 |
| "error: true is not 1" |
| #endif |
| #endif |
|
|
char a[true == 1 ? 1 : -1]; | #ifndef __bool_true_false_are_defined |
char b[false == 0 ? 1 : -1]; | "error: __bool_true_false_are_defined is not defined" |
char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | #endif |
char d[(bool) 0.5 == true ? 1 : -1]; | |
bool e = &s; | struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s; |
char f[(_Bool) 0.0 == false ? 1 : -1]; | |
char g[true]; | char a[true == 1 ? 1 : -1]; |
char h[sizeof (_Bool)]; | char b[false == 0 ? 1 : -1]; |
char i[sizeof s.t]; | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; |
enum { j = false, k = true, l = false * true, m = true * 256 }; | char d[(bool) 0.5 == true ? 1 : -1]; |
_Bool n[m]; | /* See body of main program for 'e'. */ |
char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | char f[(Bool) 0.0 == false ? 1 : -1]; |
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | char g[true]; |
#if defined __xlc__ || defined __GNUC__ | char h[sizeof (Bool)]; |
/* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 | char i[sizeof s.t]; |
reported by James Lemley on 2005-10-05; see | enum { j = false, k = true, l = false * true, m = true * 256 }; |
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html | /* The following fails for |
This test is not quite right, since xlc is allowed to | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ |
reject this program, as the initializer for xlcbug is | Bool n[m]; |
not one of the forms that C requires support for. | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; |
However, doing the test right would require a run-time | char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; |
test, and that would make cross-compilation harder. | /* Catch a bug in an HP-UX C compiler. See |
Let us hope that IBM fixes the xlc bug, and also adds | https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html |
support for this kind of constant expression. In the | https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html |
meantime, this test will reject xlc, which is OK, since | */ |
our stdbool.h substitute should suffice. We also test | Bool q = true; |
this with GCC, where it should work, to detect more | Bool *pq = &q; |
quickly whether someone messes up the test in the | bool *qq = &q; |
future. */ | ]], |
char digs[] = "0123456789"; | [[ |
int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); | bool e = &s; |
#endif | *pq |= q; *pq |= ! q; |
/* Catch a bug in an HP-UX C compiler. See | *qq |= q; *qq |= ! q; |
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | /* Refer to every declared value, to avoid compiler optimizations. */ |
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l |
*/ | + !m + !n + !o + !p + !q + !pq + !qq); |
_Bool q = true; | ]])], |
_Bool *pq = &q; | [ac_cv_header_stdbool_h=yes], |
], | [ac_cv_header_stdbool_h=no])]) |
[ | |
*pq |= q; | |
*pq |= ! q; | |
/* Refer to every declared value, to avoid compiler optimizations. */ | |
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l | |
+ !m + !n + !o + !p + !q + !pq); | |
], | |
[ac_cv_header_stdbool_h=yes], | |
[ac_cv_header_stdbool_h=no])]) | |
AC_CHECK_TYPES([_Bool]) |
AC_CHECK_TYPES([_Bool]) |
if test $ac_cv_header_stdbool_h = yes; then | ]) |
AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.]) | |
fi]) | |