diff options
Diffstat (limited to 'gl/m4/stdbool.m4')
-rw-r--r-- | gl/m4/stdbool.m4 | 137 |
1 files changed, 61 insertions, 76 deletions
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4 index 3d672d74..80d5559a 100644 --- a/gl/m4/stdbool.m4 +++ b/gl/m4/stdbool.m4 | |||
@@ -1,15 +1,17 @@ | |||
1 | # Check for stdbool.h that conforms to C99. | 1 | # Check for stdbool.h that conforms to C99. |
2 | 2 | ||
3 | dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc. | 3 | dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. |
4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
5 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
6 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
7 | 7 | ||
8 | #serial 5 | ||
9 | |||
8 | # Prepare for substituting <stdbool.h> if it is not supported. | 10 | # Prepare for substituting <stdbool.h> if it is not supported. |
9 | 11 | ||
10 | AC_DEFUN([AM_STDBOOL_H], | 12 | AC_DEFUN([AM_STDBOOL_H], |
11 | [ | 13 | [ |
12 | AC_REQUIRE([AC_HEADER_STDBOOL]) | 14 | AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) |
13 | 15 | ||
14 | # Define two additional variables used in the Makefile substitution. | 16 | # Define two additional variables used in the Makefile substitution. |
15 | 17 | ||
@@ -19,6 +21,7 @@ AC_DEFUN([AM_STDBOOL_H], | |||
19 | STDBOOL_H='stdbool.h' | 21 | STDBOOL_H='stdbool.h' |
20 | fi | 22 | fi |
21 | AC_SUBST([STDBOOL_H]) | 23 | AC_SUBST([STDBOOL_H]) |
24 | AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"]) | ||
22 | 25 | ||
23 | if test "$ac_cv_type__Bool" = yes; then | 26 | if test "$ac_cv_type__Bool" = yes; then |
24 | HAVE__BOOL=1 | 27 | HAVE__BOOL=1 |
@@ -31,85 +34,67 @@ AC_DEFUN([AM_STDBOOL_H], | |||
31 | # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. | 34 | # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. |
32 | AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) | 35 | AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) |
33 | 36 | ||
34 | # This macro is only needed in autoconf <= 2.59. Newer versions of autoconf | 37 | # This version of the macro is needed in autoconf <= 2.68. |
35 | # have this macro built-in. | ||
36 | 38 | ||
37 | AC_DEFUN([AC_HEADER_STDBOOL], | 39 | AC_DEFUN([AC_CHECK_HEADER_STDBOOL], |
38 | [AC_CACHE_CHECK([for stdbool.h that conforms to C99], | 40 | [AC_CACHE_CHECK([for stdbool.h that conforms to C99], |
39 | [ac_cv_header_stdbool_h], | 41 | [ac_cv_header_stdbool_h], |
40 | [AC_TRY_COMPILE( | 42 | [AC_COMPILE_IFELSE( |
41 | [ | 43 | [AC_LANG_PROGRAM( |
42 | #include <stdbool.h> | 44 | [[ |
43 | #ifndef bool | 45 | #include <stdbool.h> |
44 | "error: bool is not defined" | 46 | #ifndef bool |
45 | #endif | 47 | "error: bool is not defined" |
46 | #ifndef false | 48 | #endif |
47 | "error: false is not defined" | 49 | #ifndef false |
48 | #endif | 50 | "error: false is not defined" |
49 | #if false | 51 | #endif |
50 | "error: false is not 0" | 52 | #if false |
51 | #endif | 53 | "error: false is not 0" |
52 | #ifndef true | 54 | #endif |
53 | "error: true is not defined" | 55 | #ifndef true |
54 | #endif | 56 | "error: true is not defined" |
55 | #if true != 1 | 57 | #endif |
56 | "error: true is not 1" | 58 | #if true != 1 |
57 | #endif | 59 | "error: true is not 1" |
58 | #ifndef __bool_true_false_are_defined | 60 | #endif |
59 | "error: __bool_true_false_are_defined is not defined" | 61 | #ifndef __bool_true_false_are_defined |
60 | #endif | 62 | "error: __bool_true_false_are_defined is not defined" |
63 | #endif | ||
61 | 64 | ||
62 | struct s { _Bool s: 1; _Bool t; } s; | 65 | struct s { _Bool s: 1; _Bool t; } s; |
63 | 66 | ||
64 | char a[true == 1 ? 1 : -1]; | 67 | char a[true == 1 ? 1 : -1]; |
65 | char b[false == 0 ? 1 : -1]; | 68 | char b[false == 0 ? 1 : -1]; |
66 | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | 69 | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; |
67 | char d[(bool) 0.5 == true ? 1 : -1]; | 70 | char d[(bool) 0.5 == true ? 1 : -1]; |
68 | bool e = &s; | 71 | /* See body of main program for 'e'. */ |
69 | char f[(_Bool) 0.0 == false ? 1 : -1]; | 72 | char f[(_Bool) 0.0 == false ? 1 : -1]; |
70 | char g[true]; | 73 | char g[true]; |
71 | char h[sizeof (_Bool)]; | 74 | char h[sizeof (_Bool)]; |
72 | char i[sizeof s.t]; | 75 | char i[sizeof s.t]; |
73 | enum { j = false, k = true, l = false * true, m = true * 256 }; | 76 | enum { j = false, k = true, l = false * true, m = true * 256 }; |
74 | _Bool n[m]; | 77 | /* The following fails for |
75 | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | 78 | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ |
76 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | 79 | _Bool n[m]; |
77 | #if defined __xlc__ || defined __GNUC__ | 80 | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; |
78 | /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 | 81 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; |
79 | reported by James Lemley on 2005-10-05; see | 82 | /* Catch a bug in an HP-UX C compiler. See |
80 | http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html | 83 | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html |
81 | This test is not quite right, since xlc is allowed to | 84 | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html |
82 | reject this program, as the initializer for xlcbug is | 85 | */ |
83 | not one of the forms that C requires support for. | 86 | _Bool q = true; |
84 | However, doing the test right would require a run-time | 87 | _Bool *pq = &q; |
85 | test, and that would make cross-compilation harder. | 88 | ]], |
86 | Let us hope that IBM fixes the xlc bug, and also adds | 89 | [[ |
87 | support for this kind of constant expression. In the | 90 | bool e = &s; |
88 | meantime, this test will reject xlc, which is OK, since | 91 | *pq |= q; |
89 | our stdbool.h substitute should suffice. We also test | 92 | *pq |= ! q; |
90 | this with GCC, where it should work, to detect more | 93 | /* Refer to every declared value, to avoid compiler optimizations. */ |
91 | quickly whether someone messes up the test in the | 94 | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l |
92 | future. */ | 95 | + !m + !n + !o + !p + !q + !pq); |
93 | char digs[] = "0123456789"; | 96 | ]])], |
94 | int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); | ||
95 | #endif | ||
96 | /* Catch a bug in an HP-UX C compiler. See | ||
97 | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | ||
98 | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | ||
99 | */ | ||
100 | _Bool q = true; | ||
101 | _Bool *pq = &q; | ||
102 | ], | ||
103 | [ | ||
104 | *pq |= q; | ||
105 | *pq |= ! q; | ||
106 | /* Refer to every declared value, to avoid compiler optimizations. */ | ||
107 | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l | ||
108 | + !m + !n + !o + !p + !q + !pq); | ||
109 | ], | ||
110 | [ac_cv_header_stdbool_h=yes], | 97 | [ac_cv_header_stdbool_h=yes], |
111 | [ac_cv_header_stdbool_h=no])]) | 98 | [ac_cv_header_stdbool_h=no])]) |
112 | AC_CHECK_TYPES([_Bool]) | 99 | AC_CHECK_TYPES([_Bool]) |
113 | if test $ac_cv_header_stdbool_h = yes; then | 100 | ]) |
114 | AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.]) | ||
115 | fi]) | ||