Avoid test failures.
[gnulib.git] / tests / test-stdbool.c
1 /* Test of <stdbool.h> substitute.
2    Copyright (C) 2002-2007 Free Software Foundation, Inc.
3
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 2, or (at your option)
7    any later version.
8
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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
19
20 #include <config.h>
21
22 #include <stdbool.h>
23
24 #ifndef bool
25  "error: bool is not defined"
26 #endif
27 #ifndef false
28  "error: false is not defined"
29 #endif
30 #if false
31  "error: false is not 0"
32 #endif
33 #ifndef true
34  "error: true is not defined"
35 #endif
36 #if true != 1
37  "error: true is not 1"
38 #endif
39 #ifndef __bool_true_false_are_defined
40  "error: __bool_true_false_are_defined is not defined"
41 #endif
42
43 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
44 struct s { _Bool s: 1; _Bool t; } s;
45 #endif
46
47 char a[true == 1 ? 1 : -1];
48 char b[false == 0 ? 1 : -1];
49 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
50 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
51 char d[(bool) 0.5 == true ? 1 : -1];
52 bool e = &s;
53 #endif
54 char f[(_Bool) 0.0 == false ? 1 : -1];
55 char g[true];
56 char h[sizeof (_Bool)];
57 char i[sizeof s.t];
58 enum { j = false, k = true, l = false * true, m = true * 256 };
59 _Bool n[m];
60 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
61 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
62 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
63 #if defined __xlc__ || defined __GNUC__
64  /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
65     reported by James Lemley on 2005-10-05; see
66     http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
67     This test is not quite right, since xlc is allowed to
68     reject this program, as the initializer for xlcbug is
69     not one of the forms that C requires support for.
70     However, doing the test right would require a run-time
71     test, and that would make cross-compilation harder.
72     Let us hope that IBM fixes the xlc bug, and also adds
73     support for this kind of constant expression.  In the
74     meantime, this test will reject xlc, which is OK, since
75     our stdbool.h substitute should suffice.  We also test
76     this with GCC, where it should work, to detect more
77     quickly whether someone messes up the test in the
78     future.  */
79  char digs[] = "0123456789";
80  int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
81 #endif
82 #endif
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 int
91 main ()
92 {
93   return 0;
94 }