summaryrefslogtreecommitdiffstats
path: root/gl/m4/stdbool.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/stdbool.m4')
-rw-r--r--gl/m4/stdbool.m4124
1 files changed, 60 insertions, 64 deletions
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4
index 3169779..c67908a 100644
--- a/gl/m4/stdbool.m4
+++ b/gl/m4/stdbool.m4
@@ -1,15 +1,15 @@
1# Check for stdbool.h that conforms to C99. 1# Check for stdbool.h that conforms to C99.
2 2
3dnl Copyright (C) 2002-2006, 2009-2021 Free Software Foundation, Inc. 3dnl Copyright (C) 2002-2006, 2009-2022 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7 7
8#serial 8 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
12AC_DEFUN([AM_STDBOOL_H], 12AC_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 AC_REQUIRE([AC_CANONICAL_HOST])
@@ -22,20 +22,18 @@ AC_DEFUN([AM_STDBOOL_H],
22 case "$host_os" in 22 case "$host_os" in
23 solaris*) 23 solaris*)
24 if test -z "$GCC"; then 24 if test -z "$GCC"; then
25 STDBOOL_H='stdbool.h' 25 GL_GENERATE_STDBOOL_H=true
26 else 26 else
27 STDBOOL_H='' 27 GL_GENERATE_STDBOOL_H=false
28 fi 28 fi
29 ;; 29 ;;
30 *) 30 *)
31 STDBOOL_H='' 31 GL_GENERATE_STDBOOL_H=false
32 ;; 32 ;;
33 esac 33 esac
34 else 34 else
35 STDBOOL_H='stdbool.h' 35 GL_GENERATE_STDBOOL_H=true
36 fi 36 fi
37 AC_SUBST([STDBOOL_H])
38 AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
39 37
40 if test "$ac_cv_type__Bool" = yes; then 38 if test "$ac_cv_type__Bool" = yes; then
41 HAVE__BOOL=1 39 HAVE__BOOL=1
@@ -45,78 +43,76 @@ AC_DEFUN([AM_STDBOOL_H],
45 AC_SUBST([HAVE__BOOL]) 43 AC_SUBST([HAVE__BOOL])
46]) 44])
47 45
48# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. 46m4_version_prereq([2.72], [], [
49AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
50
51# This version of the macro is needed in autoconf <= 2.68.
52 47
53AC_DEFUN([AC_CHECK_HEADER_STDBOOL], 48AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
54 [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],
55 [ac_cv_header_stdbool_h], 51 [ac_cv_header_stdbool_h],
56 [AC_COMPILE_IFELSE( 52 [AC_COMPILE_IFELSE(
57 [AC_LANG_PROGRAM( 53 [AC_LANG_PROGRAM(
58 [[ 54 [[#include <stdbool.h>
59 #include <stdbool.h> 55
60 56 /* "true" and "false" should be usable in #if expressions and
61 #ifdef __cplusplus 57 integer constant expressions, and "bool" should be a valid
62 typedef bool Bool; 58 type name.
63 #else 59
64 typedef _Bool Bool; 60 Although C 1999 requires bool, true, and false to be macros,
65 #ifndef bool 61 C 2023 and C++ 2011 overrule that, so do not test for that.
66 "error: bool is not defined" 62 Although C 1999 requires __bool_true_false_are_defined and
67 #endif 63 _Bool, C 2023 says they are obsolescent, so do not require
68 #ifndef false 64 them. */
69 "error: false is not defined" 65
70 #endif 66 #if !true
71 #if false 67 #error "'true' is not true"
72 "error: false is not 0" 68 #endif
73 #endif 69 #if true != 1
74 #ifndef true 70 #error "'true' is not equal to 1"
75 "error: true is not defined"
76 #endif
77 #if true != 1
78 "error: true is not 1"
79 #endif
80 #endif 71 #endif
72 char b[true == 1 ? 1 : -1];
73 char c[true];
81 74
82 #ifndef __bool_true_false_are_defined 75 #if false
83 "error: __bool_true_false_are_defined is not defined" 76 #error "'false' is not false"
77 #endif
78 #if false != 0
79 #error "'false' is not equal to 0"
84 #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];
85 91
86 struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
87
88 char a[true == 1 ? 1 : -1];
89 char b[false == 0 ? 1 : -1];
90 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
91 char d[(bool) 0.5 == true ? 1 : -1];
92 /* See body of main program for 'e'. */
93 char f[(Bool) 0.0 == false ? 1 : -1];
94 char g[true];
95 char h[sizeof (Bool)];
96 char i[sizeof s.t];
97 enum { j = false, k = true, l = false * true, m = true * 256 };
98 /* The following fails for 92 /* The following fails for
99 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ 93 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
100 Bool n[m]; 94 bool m[h];
101 char o[sizeof n == m * sizeof n[0] ? 1 : -1]; 95 char n[sizeof m == h * sizeof m[0] ? 1 : -1];
102 char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; 96 char o[-1 - (bool) 0 < 0 ? 1 : -1];
103 /* Catch a bug in an HP-UX C compiler. See 97 /* Catch a bug in an HP-UX C compiler. See
104 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html 98 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
105 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html 99 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
106 */ 100 */
107 Bool q = true; 101 bool p = true;
108 Bool *pq = &q; 102 bool *pp = &p;
109 bool *qq = &q;
110 ]], 103 ]],
111 [[ 104 [[
112 bool e = &s; 105 bool ps = &s;
113 *pq |= q; *pq |= ! q; 106 *pp |= p;
114 *qq |= q; *qq |= ! q; 107 *pp |= ! p;
115 /* Refer to every declared value, to avoid compiler optimizations. */ 108
116 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l 109 /* Refer to every declared value, so they cannot be
117 + !m + !n + !o + !p + !q + !pq + !qq); 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);
118 ]])], 113 ]])],
119 [ac_cv_header_stdbool_h=yes], 114 [ac_cv_header_stdbool_h=yes],
120 [ac_cv_header_stdbool_h=no])]) 115 [ac_cv_header_stdbool_h=no])])
121 AC_CHECK_TYPES([_Bool]) 116])# AC_CHECK_HEADER_STDBOOL
122]) 117
118]) # m4_version_prereq 2.72