diff options
Diffstat (limited to 'gl/m4/stdbool.m4')
-rw-r--r-- | gl/m4/stdbool.m4 | 130 |
1 files changed, 74 insertions, 56 deletions
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4 index 80d5559a..c67908aa 100644 --- a/gl/m4/stdbool.m4 +++ b/gl/m4/stdbool.m4 | |||
@@ -1,27 +1,39 @@ | |||
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-2013 Free Software Foundation, Inc. | 3 | dnl Copyright (C) 2002-2006, 2009-2022 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 | 8 | #serial 9 |
9 | 9 | ||
10 | # Prepare for substituting <stdbool.h> if it is not supported. | 10 | # Prepare for substituting <stdbool.h> if it is not supported. |
11 | 11 | ||
12 | AC_DEFUN([AM_STDBOOL_H], | 12 | AC_DEFUN([gl_STDBOOL_H], |
13 | [ | 13 | [ |
14 | AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) | 14 | AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) |
15 | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
15 | 16 | ||
16 | # Define two additional variables used in the Makefile substitution. | 17 | dnl On some platforms, <stdbool.h> does not exist or does not conform to C99. |
17 | 18 | dnl On Solaris 10 with CC=cc CXX=CC, <stdbool.h> exists but is not usable | |
19 | dnl in C++ mode (and no <cstdbool> exists). In this case, we use our | ||
20 | dnl replacement, also in C mode (for binary compatibility between C and C++). | ||
18 | if test "$ac_cv_header_stdbool_h" = yes; then | 21 | if test "$ac_cv_header_stdbool_h" = yes; then |
19 | STDBOOL_H='' | 22 | case "$host_os" in |
23 | solaris*) | ||
24 | if test -z "$GCC"; then | ||
25 | GL_GENERATE_STDBOOL_H=true | ||
26 | else | ||
27 | GL_GENERATE_STDBOOL_H=false | ||
28 | fi | ||
29 | ;; | ||
30 | *) | ||
31 | GL_GENERATE_STDBOOL_H=false | ||
32 | ;; | ||
33 | esac | ||
20 | else | 34 | else |
21 | STDBOOL_H='stdbool.h' | 35 | GL_GENERATE_STDBOOL_H=true |
22 | fi | 36 | fi |
23 | AC_SUBST([STDBOOL_H]) | ||
24 | AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"]) | ||
25 | 37 | ||
26 | if test "$ac_cv_type__Bool" = yes; then | 38 | if test "$ac_cv_type__Bool" = yes; then |
27 | HAVE__BOOL=1 | 39 | HAVE__BOOL=1 |
@@ -31,70 +43,76 @@ AC_DEFUN([AM_STDBOOL_H], | |||
31 | AC_SUBST([HAVE__BOOL]) | 43 | AC_SUBST([HAVE__BOOL]) |
32 | ]) | 44 | ]) |
33 | 45 | ||
34 | # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. | 46 | m4_version_prereq([2.72], [], [ |
35 | AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) | ||
36 | |||
37 | # This version of the macro is needed in autoconf <= 2.68. | ||
38 | 47 | ||
39 | AC_DEFUN([AC_CHECK_HEADER_STDBOOL], | 48 | AC_DEFUN([AC_CHECK_HEADER_STDBOOL], |
40 | [AC_CACHE_CHECK([for stdbool.h that conforms to C99], | 49 | [AC_CHECK_TYPES([_Bool]) |
50 | AC_CACHE_CHECK([for stdbool.h that conforms to C99 or later], | ||
41 | [ac_cv_header_stdbool_h], | 51 | [ac_cv_header_stdbool_h], |
42 | [AC_COMPILE_IFELSE( | 52 | [AC_COMPILE_IFELSE( |
43 | [AC_LANG_PROGRAM( | 53 | [AC_LANG_PROGRAM( |
44 | [[ | 54 | [[#include <stdbool.h> |
45 | #include <stdbool.h> | 55 | |
46 | #ifndef bool | 56 | /* "true" and "false" should be usable in #if expressions and |
47 | "error: bool is not defined" | 57 | integer constant expressions, and "bool" should be a valid |
58 | type name. | ||
59 | |||
60 | Although C 1999 requires bool, true, and false to be macros, | ||
61 | C 2023 and C++ 2011 overrule that, so do not test for that. | ||
62 | Although C 1999 requires __bool_true_false_are_defined and | ||
63 | _Bool, C 2023 says they are obsolescent, so do not require | ||
64 | them. */ | ||
65 | |||
66 | #if !true | ||
67 | #error "'true' is not true" | ||
48 | #endif | 68 | #endif |
49 | #ifndef false | 69 | #if true != 1 |
50 | "error: false is not defined" | 70 | #error "'true' is not equal to 1" |
51 | #endif | 71 | #endif |
72 | char b[true == 1 ? 1 : -1]; | ||
73 | char c[true]; | ||
74 | |||
52 | #if false | 75 | #if false |
53 | "error: false is not 0" | 76 | #error "'false' is not false" |
54 | #endif | 77 | #endif |
55 | #ifndef true | 78 | #if false != 0 |
56 | "error: true is not defined" | 79 | #error "'false' is not equal to 0" |
57 | #endif | ||
58 | #if true != 1 | ||
59 | "error: true is not 1" | ||
60 | #endif | ||
61 | #ifndef __bool_true_false_are_defined | ||
62 | "error: __bool_true_false_are_defined is not defined" | ||
63 | #endif | 80 | #endif |
81 | char d[false == 0 ? 1 : -1]; | ||
82 | |||
83 | enum { e = false, f = true, g = false * true, h = true * 256 }; | ||
84 | |||
85 | char i[(bool) 0.5 == true ? 1 : -1]; | ||
86 | char j[(bool) 0.0 == false ? 1 : -1]; | ||
87 | char k[sizeof (bool) > 0 ? 1 : -1]; | ||
88 | |||
89 | struct sb { bool s: 1; bool t; } s; | ||
90 | char l[sizeof s.t > 0 ? 1 : -1]; | ||
64 | 91 | ||
65 | struct s { _Bool s: 1; _Bool t; } s; | ||
66 | |||
67 | char a[true == 1 ? 1 : -1]; | ||
68 | char b[false == 0 ? 1 : -1]; | ||
69 | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | ||
70 | char d[(bool) 0.5 == true ? 1 : -1]; | ||
71 | /* See body of main program for 'e'. */ | ||
72 | char f[(_Bool) 0.0 == false ? 1 : -1]; | ||
73 | char g[true]; | ||
74 | char h[sizeof (_Bool)]; | ||
75 | char i[sizeof s.t]; | ||
76 | enum { j = false, k = true, l = false * true, m = true * 256 }; | ||
77 | /* The following fails for | 92 | /* The following fails for |
78 | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ | 93 | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ |
79 | _Bool n[m]; | 94 | bool m[h]; |
80 | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | 95 | char n[sizeof m == h * sizeof m[0] ? 1 : -1]; |
81 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | 96 | char o[-1 - (bool) 0 < 0 ? 1 : -1]; |
82 | /* Catch a bug in an HP-UX C compiler. See | 97 | /* Catch a bug in an HP-UX C compiler. See |
83 | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | 98 | https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html |
84 | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | 99 | https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html |
85 | */ | 100 | */ |
86 | _Bool q = true; | 101 | bool p = true; |
87 | _Bool *pq = &q; | 102 | bool *pp = &p; |
88 | ]], | 103 | ]], |
89 | [[ | 104 | [[ |
90 | bool e = &s; | 105 | bool ps = &s; |
91 | *pq |= q; | 106 | *pp |= p; |
92 | *pq |= ! q; | 107 | *pp |= ! p; |
93 | /* Refer to every declared value, to avoid compiler optimizations. */ | 108 | |
94 | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l | 109 | /* Refer to every declared value, so they cannot be |
95 | + !m + !n + !o + !p + !q + !pq); | 110 | discarded as unused. */ |
111 | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !j + !k | ||
112 | + !l + !m + !n + !o + !p + !pp + !ps); | ||
96 | ]])], | 113 | ]])], |
97 | [ac_cv_header_stdbool_h=yes], | 114 | [ac_cv_header_stdbool_h=yes], |
98 | [ac_cv_header_stdbool_h=no])]) | 115 | [ac_cv_header_stdbool_h=no])]) |
99 | AC_CHECK_TYPES([_Bool]) | 116 | ])# AC_CHECK_HEADER_STDBOOL |
100 | ]) | 117 | |
118 | ]) # m4_version_prereq 2.72 | ||