1 /* Test for _Bool and <stdbool.h> in C99. */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
4 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
6 /* _Bool must be a builtin type. */
12 /* Three macros must be integer constant expressions suitable for use
16 #if !defined(true) || (true != 1)
17 #error "bad stdbool true" /* { dg-bogus "#error" "bad stdbool.h" } */
20 #if !defined(false) || (false != 0)
21 #error "bad stdbool false" /* { dg-bogus "#error" "bad stdbool.h" } */
24 #if !defined(__bool_true_false_are_defined) || (__bool_true_false_are_defined != 1)
25 #error "bad stdbool __bool_true_false_are_defined" /* { dg-bogus "#error" "bad stdbool.h" } */
30 int c
= __bool_true_false_are_defined
;
37 #define str(x) xstr(x)
41 extern void abort (void);
42 extern void exit (int);
43 extern int strcmp (const char *, const char *);
48 /* The macro `bool' must expand to _Bool. */
49 const char *t
= str (bool);
51 if (strcmp (t
, "_Bool"))
53 if (a
!= 1 || b
!= 0 || c
!= 1)
55 /* Casts to _Bool have a specified behavior. */
56 if ((int)(_Bool
)2 != 1)
58 if ((int)(_Bool
)0.2 != 1)
60 /* Pointers may be assigned to _Bool. */
63 /* _Bool may be used to subscript arrays. */
74 /* Test increment and decrement operators. */
111 /* Test unary + - ~ !. */
139 /* Test arithmetic * / % + - (which all apply promotions). */
154 /* Test bitwise shift << >>. */
160 /* Test relational and equality operators < > <= >= == !=. */
163 if (u
< v
|| u
> v
|| !(u
<= v
) || !(u
>= v
) || !(u
== v
) || u
!= v
)
167 if (!(u
< v
) || u
> v
|| !(u
<= v
) || u
>= v
|| u
== v
|| !(u
!= v
))
169 /* Test bitwise operators & ^ |. */
179 /* Test logical && ||. */
194 /* Test conditional ? :. */
196 if ((u
? 4 : 7) != 7)
200 if ((1 ? u
: v
) != 1)
202 if ((1 ? 4 : u
) != 4)
204 /* Test assignment operators = *= /= %= += -= <<= >>= &= ^= |=. */
231 /* Test comma expressions. */
235 /* Test bitfields. */
238 for (i
= 0; i
< sizeof (struct foo
); i
++)
239 *((unsigned char *)&sf
+ i
) = (unsigned char) -1;