2 Copyright (C) 2002-2007, 2009-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 /* Define ADDRESS_CHECK_OKAY if it is OK to assign an address to a 'bool'
20 and this does not generate a warning (because we want this test to succeed
21 even when using gcc's -Werror). */
22 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) \
23 || (__clang_major__ >= 4)
24 /* We can silence the warning. */
25 # pragma GCC diagnostic ignored "-Waddress"
26 # define ADDRESS_CHECK_OKAY
27 #elif defined __GNUC__ || defined __clang__
28 /* There may be a warning. */
30 /* Ignore warnings from other compilers. */
31 # define ADDRESS_CHECK_OKAY
41 "error: false is not 0"
44 "error: true is not 1"
47 /* Several tests cannot be guaranteed with gnulib's <stdbool.h>, at
48 least, not for all compilers and compiler options. */
49 #if ((HAVE_C_BOOL || defined __cplusplus \
50 || HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__) \
51 && !(defined _MSC_VER || defined __SUNPRO_C))
52 # define WORKING_BOOL 1
54 # define WORKING_BOOL 0
58 struct s
{ bool s
: 1; bool t
; } s
;
61 char a
[true == 1 ? 1 : -1];
62 char b
[false == 0 ? 1 : -1];
64 char d
[(bool) 0.5 == true ? 1 : -1];
65 # ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning. */
66 /* C99 may plausibly be interpreted as not requiring support for a cast from
67 a variable's address to bool in a static initializer. So treat it like a
69 # if defined __GNUC__ || defined __clang__
73 char f
[(bool) 0.0 == false ? 1 : -1];
76 char h
[sizeof (bool)];
80 enum { j
= false, k
= true, l
= false * true, m
= true * 256 };
82 char o
[sizeof n
== m
* sizeof n
[0] ? 1 : -1];
83 char p
[-1 - (bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
84 /* Catch a bug in an HP-UX C compiler. See
85 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
86 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
97 # ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning. */
98 /* A cast from a variable's address to bool is valid in expressions. */
107 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
108 reported by James Lemley on 2005-10-05; see
109 https://lists.gnu.org/r/bug-coreutils/2005-10/msg00086.html
110 This is a runtime test, since a corresponding compile-time
111 test would rely on initializer extensions. */
113 char digs
[] = "0123456789";
114 if (&(digs
+ 5)[-2 + (bool) 1] != &digs
[4])