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