1 // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-linux-gnu -fsyntax-only \
2 // RUN: -Wtautological-unsigned-enum-zero-compare \
3 // RUN: -verify=unsigned,unsigned-signed %s
4 // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only \
5 // RUN: -Wtautological-unsigned-enum-zero-compare \
6 // RUN: -verify=unsigned-signed %s
7 // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only \
8 // RUN: -verify=silence %s
10 // silence-no-diagnostics
13 // On Windows, all enumerations have a fixed underlying type, which is 'int'
14 // if not otherwise specified, so A is identical to C on Windows. Otherwise,
15 // we follow the C++ rules, which say that the only valid values of A are 0
17 enum A
{ A_foo
= 0, A_bar
, };
20 enum B
: unsigned { B_foo
= 0, B_bar
, };
23 enum C
: signed { C_foo
= 0, C_bar
, };
26 if (a
< 0) // unsigned-warning {{comparison of unsigned enum expression < 0 is always false}}
32 if (0 <= a
) // unsigned-warning {{comparison of 0 <= unsigned enum expression is always true}}
36 if (0 > a
) // unsigned-warning {{comparison of 0 > unsigned enum expression is always false}}
38 if (a
>= 0) // unsigned-warning {{comparison of unsigned enum expression >= 0 is always true}}
43 // FIXME: As below, the issue here is that the enumeration is promoted to
45 if (a
< 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
51 if (0U <= a
) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
55 if (0U > a
) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
57 if (a
>= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
62 if (b
< 0) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
68 if (0 <= b
) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
72 if (0 > b
) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
74 if (b
>= 0) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
79 if (b
< 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
85 if (0U <= b
) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
89 if (0U > b
) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
91 if (b
>= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
113 // FIXME: These diagnostics are terrible. The issue here is that the signed
114 // enumeration value was promoted to an unsigned type.
115 if (c
< 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
121 if (0U <= c
) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
125 if (0U > c
) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
127 if (c
>= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
135 namespace crash_enum_zero_width
{
142 // used to crash in llvm::APSInt::getMaxValue()
143 if (a
< 0) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
148 } // namespace crash_enum_zero_width