1 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -Wtautological-constant-in-range-compare -verify %s
2 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -Wtautological-constant-in-range-compare -verify %s
3 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s
4 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s
5 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -Wtype-limits -verify %s
6 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-type-limits -verify %s
13 // expected-no-diagnostics
15 // If we promote to unsigned, it doesn't matter whether the enum's underlying
17 if (a
< 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
23 if (0U <= a
) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
27 if (0U > a
) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
29 if (a
>= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
36 if (4294967295U >= a
) // expected-warning {{comparison 4294967295 >= 'enum A' is always true}}
38 if (a
> 4294967295U) // expected-warning {{comparison 'enum A' > 4294967295 is always false}}
42 if (a
<= 4294967295U) // expected-warning {{comparison 'enum A' <= 4294967295 is always true}}
48 if (4294967295U < a
) // expected-warning {{comparison 4294967295 < 'enum A' is always false}}
69 #if defined(UNSIGNED) && !defined(SILENCE)
70 if (a
< 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
76 if (0 <= a
) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
80 if (0 > a
) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
82 if (a
>= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
89 if (4294967295 >= a
) // expected-warning {{comparison 4294967295 >= 'enum A' is always true}}
91 if (a
> 4294967295) // expected-warning {{comparison 'enum A' > 4294967295 is always false}}
95 if (a
<= 4294967295) // expected-warning {{comparison 'enum A' <= 4294967295 is always true}}
101 if (4294967295 < a
) // expected-warning {{comparison 4294967295 < 'enum A' is always false}}
103 #else // SIGNED || SILENCE
122 if (a
< 4294967295) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always true}}
124 if (4294967295 >= a
) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always true}}
126 if (a
> 4294967295) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always false}}
128 if (4294967295 <= a
) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always false}}
130 if (a
<= 4294967295) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always true}}
132 if (4294967295 > a
) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always true}}
134 if (a
>= 4294967295) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always false}}
136 if (4294967295 < a
) // expected-warning {{comparison of constant 4294967295 with expression of type 'enum A' is always false}}
158 #if defined(SIGNED) && !defined(SILENCE)
159 if (a
< -2147483648) // expected-warning {{comparison 'enum A' < -2147483648 is always false}}
161 if (-2147483648 >= a
)
165 if (-2147483648 <= a
) // expected-warning {{comparison -2147483648 <= 'enum A' is always true}}
167 if (a
<= -2147483648)
169 if (-2147483648 > a
) // expected-warning {{comparison -2147483648 > 'enum A' is always false}}
171 if (a
>= -2147483648) // expected-warning {{comparison 'enum A' >= -2147483648 is always true}}
178 if (2147483647 >= a
) // expected-warning {{comparison 2147483647 >= 'enum A' is always true}}
180 if (a
> 2147483647) // expected-warning {{comparison 'enum A' > 2147483647 is always false}}
184 if (a
<= 2147483647) // expected-warning {{comparison 'enum A' <= 2147483647 is always true}}
190 if (2147483647 < a
) // expected-warning {{comparison 2147483647 < 'enum A' is always false}}
192 #elif defined(UNSIGNED) && !defined(SILENCE)
194 if (a
< -2147483648) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always false}}
196 if (-2147483648 >= a
) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always false}}
198 if (a
> -2147483648) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always true}}
200 if (-2147483648 <= a
) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always true}}
202 if (a
<= -2147483648) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always false}}
204 if (-2147483648 > a
) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always false}}
206 if (a
>= -2147483648) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always true}}
208 if (-2147483648 < a
) // expected-warning {{comparison of constant -2147483648 with expression of type 'enum A' is always true}}
213 if (-2147483648 >= a
)
217 if (-2147483648 <= a
)
219 if (a
<= -2147483648)
223 if (a
>= -2147483648)
250 // https://bugs.llvm.org/show_bug.cgi?id=35009
255 // in C, this should not warn.