Commit | Line | Data |
---|---|---|
16c3e636 PE |
1 | # Check for stdbool.h that conforms to C99. |
2 | ||
3 | dnl Copyright (C) 2002-2006, 2009-2011 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 3 | |
9 | ||
10 | # Prepare for substituting <stdbool.h> if it is not supported. | |
11 | ||
12 | AC_DEFUN([AM_STDBOOL_H], | |
13 | [ | |
14 | AC_REQUIRE([AC_HEADER_STDBOOL]) | |
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 | ||
36 | # This version of the macro is needed in autoconf <= 2.67. Autoconf has | |
37 | # it built in since 2.60, but we want the tweaks from the 2.68 version | |
38 | # to avoid rejecting xlc and clang due to relying on extensions. | |
39 | ||
40 | AC_DEFUN([AC_HEADER_STDBOOL], | |
41 | [AC_CACHE_CHECK([for stdbool.h that conforms to C99], | |
42 | [ac_cv_header_stdbool_h], | |
43 | [AC_COMPILE_IFELSE( | |
44 | [AC_LANG_PROGRAM( | |
45 | [[ | |
46 | #include <stdbool.h> | |
47 | #ifndef bool | |
48 | "error: bool is not defined" | |
49 | #endif | |
50 | #ifndef false | |
51 | "error: false is not defined" | |
52 | #endif | |
53 | #if false | |
54 | "error: false is not 0" | |
55 | #endif | |
56 | #ifndef true | |
57 | "error: true is not defined" | |
58 | #endif | |
59 | #if true != 1 | |
60 | "error: true is not 1" | |
61 | #endif | |
62 | #ifndef __bool_true_false_are_defined | |
63 | "error: __bool_true_false_are_defined is not defined" | |
64 | #endif | |
65 | ||
66 | struct s { _Bool s: 1; _Bool t; } s; | |
67 | ||
68 | char a[true == 1 ? 1 : -1]; | |
69 | char b[false == 0 ? 1 : -1]; | |
70 | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | |
71 | char d[(bool) 0.5 == true ? 1 : -1]; | |
72 | /* See body of main program for 'e'. */ | |
73 | char f[(_Bool) 0.0 == false ? 1 : -1]; | |
74 | char g[true]; | |
75 | char h[sizeof (_Bool)]; | |
76 | char i[sizeof s.t]; | |
77 | enum { j = false, k = true, l = false * true, m = true * 256 }; | |
78 | /* The following fails for | |
79 | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ | |
80 | _Bool n[m]; | |
81 | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | |
82 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | |
83 | /* Catch a bug in an HP-UX C compiler. See | |
84 | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | |
85 | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | |
86 | */ | |
87 | _Bool q = true; | |
88 | _Bool *pq = &q; | |
89 | ]], | |
90 | [[ | |
91 | bool e = &s; | |
92 | *pq |= q; | |
93 | *pq |= ! q; | |
94 | /* Refer to every declared value, to avoid compiler optimizations. */ | |
95 | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l | |
96 | + !m + !n + !o + !p + !q + !pq); | |
97 | ]])], | |
98 | [ac_cv_header_stdbool_h=yes], | |
99 | [ac_cv_header_stdbool_h=no])]) | |
100 | AC_CHECK_TYPES([_Bool]) | |
101 | if test $ac_cv_header_stdbool_h = yes; then | |
102 | AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.]) | |
103 | fi]) |