* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
[official-gcc.git] / gcc / testsuite / c-c++-common / Wbool-compare-1.c
blob2f435f651e682cb9dbc0e7c9cc22863ed2ea3208
1 /* PR c++/62153 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall" } */
5 #ifndef __cplusplus
6 # define bool _Bool
7 # define true 1
8 # define false 0
9 #endif
11 extern bool foo (void);
12 bool r;
14 enum { E = 4 };
16 void
17 fn1 (bool b)
19 r = b == 2; /* { dg-warning "with boolean expression is always false" } */
20 r = b != 2; /* { dg-warning "with boolean expression is always true" } */
21 r = b < 2; /* { dg-warning "with boolean expression is always true" } */
22 r = b > 2; /* { dg-warning "with boolean expression is always false" } */
23 r = b <= 2; /* { dg-warning "with boolean expression is always true" } */
24 r = b >= 2; /* { dg-warning "with boolean expression is always false" } */
26 r = b == -1; /* { dg-warning "with boolean expression is always false" } */
27 r = b != -1; /* { dg-warning "with boolean expression is always true" } */
28 r = b < -1; /* { dg-warning "with boolean expression is always false" } */
29 r = b > -1; /* { dg-warning "with boolean expression is always true" } */
30 r = b <= -1; /* { dg-warning "with boolean expression is always false" } */
31 r = b >= -1; /* { dg-warning "with boolean expression is always true" } */
33 r = foo () == 2; /* { dg-warning "with boolean expression is always false" } */
34 r = foo () != 2; /* { dg-warning "with boolean expression is always true" } */
35 r = foo () < 2; /* { dg-warning "with boolean expression is always true" } */
36 r = foo () > 2; /* { dg-warning "with boolean expression is always false" } */
37 r = foo () <= 2; /* { dg-warning "with boolean expression is always true" } */
38 r = foo () >= 2; /* { dg-warning "with boolean expression is always false" } */
40 r = b == E; /* { dg-warning "with boolean expression is always false" } */
41 r = b != E; /* { dg-warning "with boolean expression is always true" } */
42 r = b < E; /* { dg-warning "with boolean expression is always true" } */
43 r = b > E; /* { dg-warning "with boolean expression is always false" } */
44 r = b <= E; /* { dg-warning "with boolean expression is always true" } */
45 r = b >= E; /* { dg-warning "with boolean expression is always false" } */
47 /* Swap LHS and RHS. */
48 r = 2 == b; /* { dg-warning "with boolean expression is always false" } */
49 r = 2 != b; /* { dg-warning "with boolean expression is always true" } */
50 r = 2 < b; /* { dg-warning "with boolean expression is always false" } */
51 r = 2 > b; /* { dg-warning "with boolean expression is always true" } */
52 r = 2 <= b; /* { dg-warning "with boolean expression is always false" } */
53 r = 2 >= b; /* { dg-warning "with boolean expression is always true" } */
55 r = -1 == b; /* { dg-warning "with boolean expression is always false" } */
56 r = -1 != b; /* { dg-warning "with boolean expression is always true" } */
57 r = -1 < b; /* { dg-warning "with boolean expression is always true" } */
58 r = -1 > b; /* { dg-warning "with boolean expression is always false" } */
59 r = -1 <= b; /* { dg-warning "with boolean expression is always true" } */
60 r = -1 >= b; /* { dg-warning "with boolean expression is always false" } */
62 r = E == b; /* { dg-warning "with boolean expression is always false" } */
63 r = E != b; /* { dg-warning "with boolean expression is always true" } */
64 r = E < b; /* { dg-warning "with boolean expression is always false" } */
65 r = E > b; /* { dg-warning "with boolean expression is always true" } */
66 r = E <= b; /* { dg-warning "with boolean expression is always false" } */
67 r = E >= b; /* { dg-warning "with boolean expression is always true" } */
69 /* These are of course fine. */
70 r = b == false;
71 r = b != false;
72 r = b == true;
73 r = b != true;
75 r = b <= false;
76 r = b > false;
77 r = b < true;
78 r = b >= true;
81 void
82 fn2 (int i1, int i2)
84 r = (i1 == i2) == 2; /* { dg-warning "with boolean expression is always false" } */
85 r = (i1 == i2) != 2; /* { dg-warning "with boolean expression is always true" } */
86 r = (i1 == i2) < 2; /* { dg-warning "with boolean expression is always true" } */
87 r = (i1 == i2) > 2; /* { dg-warning "with boolean expression is always false" } */
88 r = (i1 == i2) <= 2; /* { dg-warning "with boolean expression is always true" } */
89 r = (i1 == i2) >= 2; /* { dg-warning "with boolean expression is always false" } */
91 r = (i1 == i2) == -1; /* { dg-warning "with boolean expression is always false" } */
92 r = (i1 == i2) != -1; /* { dg-warning "with boolean expression is always true" } */
93 r = (i1 == i2) < -1; /* { dg-warning "with boolean expression is always false" } */
94 r = (i1 == i2) > -1; /* { dg-warning "with boolean expression is always true" } */
95 r = (i1 == i2) <= -1; /* { dg-warning "with boolean expression is always false" } */
96 r = (i1 == i2) >= -1; /* { dg-warning "with boolean expression is always true" } */
98 r = (i1 == i2) == E; /* { dg-warning "with boolean expression is always false" } */
99 r = (i1 == i2) != E; /* { dg-warning "with boolean expression is always true" } */
100 r = (i1 == i2) < E; /* { dg-warning "with boolean expression is always true" } */
101 r = (i1 == i2) > E; /* { dg-warning "with boolean expression is always false" } */
102 r = (i1 == i2) <= E; /* { dg-warning "with boolean expression is always true" } */
103 r = (i1 == i2) >= E; /* { dg-warning "with boolean expression is always false" } */
106 void
107 fn3 (int n, bool b)
109 /* Don't warn here. */
110 r = b == n;
111 r = b != n;
112 r = b < n;
113 r = b > n;
114 r = b <= n;
115 r = b >= n;
117 r = n == E;
118 r = n != E;
119 r = n < E;
120 r = n > E;
121 r = n <= E;
122 r = n >= E;