b64da1f7b43a00be2a76bc509274d822b0ac3316
[platform/upstream/gcc.git] / gcc / testsuite / gcc.dg / c2x-bool-1.c
1 /* Test macro expansions in <stdbool.h> in C2x.  */
2 /* { dg-do run } */
3 /* { dg-options "-std=c2x -pedantic-errors" } */
4
5 #include <stdbool.h>
6
7 #define str(x) xstr(x)
8 #define xstr(x) #x
9
10 extern void abort (void);
11 extern void exit (int);
12 extern int strcmp (const char *, const char *);
13
14 #if false - 1 < 0
15 #error "false signed in #if"
16 #endif
17
18 #if false != 0
19 #error "false not 0 in #if"
20 #endif
21
22 #if true - 2 < 0
23 #error "true signed in #if"
24 #endif
25
26 #if true != 1
27 #error "true not 1 in #if"
28 #endif
29
30 int
31 main (void)
32 {
33   if (strcmp (str (bool), "_Bool") != 0)
34     abort ();
35   if (_Generic (true, _Bool : 1) != 1)
36     abort ();
37   if (true != 1)
38     abort ();
39   if (strcmp (str (true), "((_Bool)+1u)") != 0)
40     abort ();
41   if (_Generic (false, _Bool : 1) != 1)
42     abort ();
43   if (false != 0)
44     abort ();
45   if (strcmp (str (false), "((_Bool)+0u)") != 0)
46     abort ();
47   if (strcmp (str (__bool_true_false_are_defined), "1") != 0)
48     abort ();
49   exit (0);
50 }