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
;
39 #define str(x) xstr(x)
43 extern void abort (void);
44 extern void exit (int);
45 extern int strcmp (const char *, const char *);
50 /* The macro `bool' must expand to _Bool. */
51 const char *t
= str (bool);
53 if (strcmp (t
, "_Bool"))
55 if (a
!= 1 || b
!= 0 || c
!= 1)
57 /* Casts to _Bool have a specified behaviour. */
58 if ((int)(_Bool
)2 != 1)
60 if ((int)(_Bool
)0.2 != 1)
62 /* Pointers may be assigned to _Bool. */
65 /* _Bool may be used to subscript arrays. */
76 /* Test increment and decrement operators. */
113 /* Test unary + - ~ !. */
141 /* Test arithmetic * / % + - (which all apply promotions). */
156 /* Test bitwise shift << >>. */
162 /* Test relational and equality operators < > <= >= == !=. */
165 if (u
< v
|| u
> v
|| !(u
<= v
) || !(u
>= v
) || !(u
== v
) || u
!= v
)
169 if (!(u
< v
) || u
> v
|| !(u
<= v
) || u
>= v
|| u
== v
|| !(u
!= v
))
171 /* Test bitwise operators & ^ |. */
181 /* Test logical && ||. */
196 /* Test conditional ? :. */
198 if ((u
? 4 : 7) != 7)
202 if ((1 ? u
: v
) != 1)
204 if ((1 ? 4 : u
) != 4)
206 /* Test assignment operators = *= /= %= += -= <<= >>= &= ^= |=. */
231 /* ??? A bit queer, since this gets optimized to ((u = (u != 3)) != 1)
232 early in semantic analysis, which then yields the warning below. */
233 if ((u
^= 3) != 1) /* { dg-warning "always true due to limited range" } */
235 /* Test comma expressions. */
239 /* Test bitfields. */
242 for (i
= 0; i
< sizeof (struct foo
); i
++)
243 *((unsigned char *)&sf
+ i
) = (unsigned char) -1;