1*67e74705SXin Li // RUN: %clang_cc1 %s -fsyntax-only -verify
2*67e74705SXin Li
3*67e74705SXin Li enum Foo { FooA, FooB, FooC };
4*67e74705SXin Li enum Bar { BarD, BarE, BarF };
5*67e74705SXin Li enum { AnonAA = 42, AnonAB = 43 };
6*67e74705SXin Li enum { AnonBA = 44, AnonBB = 45 };
7*67e74705SXin Li
8*67e74705SXin Li namespace name1 {
9*67e74705SXin Li enum Foo {F1, F2, F3};
10*67e74705SXin Li enum Baz {B1, B2, B3};
11*67e74705SXin Li }
12*67e74705SXin Li
13*67e74705SXin Li namespace name2 {
14*67e74705SXin Li enum Baz {B1, B2, B3};
15*67e74705SXin Li }
16*67e74705SXin Li
17*67e74705SXin Li using name1::Baz;
18*67e74705SXin Li using name1::B1;
19*67e74705SXin Li using name2::B2;
20*67e74705SXin Li typedef name1::Foo oneFoo;
21*67e74705SXin Li typedef name1::Foo twoFoo;
22*67e74705SXin Li Foo getFoo();
23*67e74705SXin Li Bar getBar();
24*67e74705SXin Li
test()25*67e74705SXin Li void test () {
26*67e74705SXin Li Foo x = FooA;
27*67e74705SXin Li Bar y = BarD;
28*67e74705SXin Li Baz z = name1::B3;
29*67e74705SXin Li name1::Foo a;
30*67e74705SXin Li oneFoo b;
31*67e74705SXin Li twoFoo c;
32*67e74705SXin Li
33*67e74705SXin Li while (x == FooA);
34*67e74705SXin Li while (y == BarD);
35*67e74705SXin Li while (a == name1::F1);
36*67e74705SXin Li while (z == name1::B2);
37*67e74705SXin Li while (a == b);
38*67e74705SXin Li while (a == c);
39*67e74705SXin Li while (b == c);
40*67e74705SXin Li while (B1 == name1::B2);
41*67e74705SXin Li while (B2 == name2::B1);
42*67e74705SXin Li while (x == AnonAA); // expected-warning {{comparison of constant 'AnonAA' (42) with expression of type 'Foo' is always false}}
43*67e74705SXin Li while (AnonBB == y); // expected-warning {{comparison of constant 'AnonBB' (45) with expression of type 'Bar' is always false}}
44*67e74705SXin Li while (AnonAA == AnonAB);
45*67e74705SXin Li while (AnonAB == AnonBA);
46*67e74705SXin Li while (AnonBB == AnonAA);
47*67e74705SXin Li
48*67e74705SXin Li while ((x) == FooA);
49*67e74705SXin Li while ((y) == BarD);
50*67e74705SXin Li while ((a) == name1::F1);
51*67e74705SXin Li while (z == (name1::B2));
52*67e74705SXin Li while (a == (b));
53*67e74705SXin Li while (a == (c));
54*67e74705SXin Li while ((b) == (c));
55*67e74705SXin Li while ((B1) == (name1::B2));
56*67e74705SXin Li while ((B2) == (name2::B1));
57*67e74705SXin Li
58*67e74705SXin Li while (((x)) == FooA);
59*67e74705SXin Li while ((y) == (BarD));
60*67e74705SXin Li while ((a) == (name1::F1));
61*67e74705SXin Li while (z == (name1::B2));
62*67e74705SXin Li while ((a) == ((((b)))));
63*67e74705SXin Li while (((a)) == (c));
64*67e74705SXin Li while ((b) == (((c))));
65*67e74705SXin Li while ((((((B1))))) == (((name1::B2))));
66*67e74705SXin Li while (B2 == ((((((name2::B1)))))));
67*67e74705SXin Li
68*67e74705SXin Li while (B1 == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
69*67e74705SXin Li while (name1::B2 == name2::B3); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
70*67e74705SXin Li while (z == name2::B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
71*67e74705SXin Li
72*67e74705SXin Li while (((((B1)))) == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
73*67e74705SXin Li while (name1::B2 == (name2::B3)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
74*67e74705SXin Li while (z == ((((name2::B2))))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
75*67e74705SXin Li
76*67e74705SXin Li while ((((B1))) == (((B2)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
77*67e74705SXin Li while ((name1::B2) == (((name2::B3)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
78*67e74705SXin Li while ((((z))) == (name2::B2)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
79*67e74705SXin Li
80*67e74705SXin Li while (x == a); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'name1::Foo')}}
81*67e74705SXin Li while (x == b); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'oneFoo' (aka 'name1::Foo'))}}
82*67e74705SXin Li while (x == c); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'twoFoo' (aka 'name1::Foo'))}}
83*67e74705SXin Li
84*67e74705SXin Li while (x == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
85*67e74705SXin Li while (x != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
86*67e74705SXin Li while (x >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
87*67e74705SXin Li while (x <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
88*67e74705SXin Li while (x > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
89*67e74705SXin Li while (x < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
90*67e74705SXin Li
91*67e74705SXin Li while (FooB == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
92*67e74705SXin Li while (FooB != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
93*67e74705SXin Li while (FooB >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
94*67e74705SXin Li while (FooB <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
95*67e74705SXin Li while (FooB > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
96*67e74705SXin Li while (FooB < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
97*67e74705SXin Li
98*67e74705SXin Li while (FooB == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
99*67e74705SXin Li while (FooB != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
100*67e74705SXin Li while (FooB >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
101*67e74705SXin Li while (FooB <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
102*67e74705SXin Li while (FooB > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
103*67e74705SXin Li while (FooB < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
104*67e74705SXin Li
105*67e74705SXin Li while (x == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
106*67e74705SXin Li while (x != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
107*67e74705SXin Li while (x >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
108*67e74705SXin Li while (x <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
109*67e74705SXin Li while (x > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
110*67e74705SXin Li while (x < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
111*67e74705SXin Li
112*67e74705SXin Li while (getFoo() == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
113*67e74705SXin Li while (getFoo() != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
114*67e74705SXin Li while (getFoo() >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
115*67e74705SXin Li while (getFoo() <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
116*67e74705SXin Li while (getFoo() > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
117*67e74705SXin Li while (getFoo() < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
118*67e74705SXin Li
119*67e74705SXin Li while (getFoo() == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
120*67e74705SXin Li while (getFoo() != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
121*67e74705SXin Li while (getFoo() >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
122*67e74705SXin Li while (getFoo() <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
123*67e74705SXin Li while (getFoo() > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
124*67e74705SXin Li while (getFoo() < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
125*67e74705SXin Li
126*67e74705SXin Li while (getFoo() == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
127*67e74705SXin Li while (getFoo() != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
128*67e74705SXin Li while (getFoo() >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
129*67e74705SXin Li while (getFoo() <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
130*67e74705SXin Li while (getFoo() > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
131*67e74705SXin Li while (getFoo() < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
132*67e74705SXin Li
133*67e74705SXin Li while (FooB == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
134*67e74705SXin Li while (FooB != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
135*67e74705SXin Li while (FooB >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
136*67e74705SXin Li while (FooB <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
137*67e74705SXin Li while (FooB > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
138*67e74705SXin Li while (FooB < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
139*67e74705SXin Li
140*67e74705SXin Li while (x == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
141*67e74705SXin Li while (x != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
142*67e74705SXin Li while (x >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
143*67e74705SXin Li while (x <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
144*67e74705SXin Li while (x > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
145*67e74705SXin Li while (x < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
146*67e74705SXin Li
147*67e74705SXin Li
148*67e74705SXin Li
149*67e74705SXin Li while (y == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
150*67e74705SXin Li while (y != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
151*67e74705SXin Li while (y >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
152*67e74705SXin Li while (y <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
153*67e74705SXin Li while (y > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
154*67e74705SXin Li while (y < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
155*67e74705SXin Li
156*67e74705SXin Li while (y == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
157*67e74705SXin Li while (y != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
158*67e74705SXin Li while (y >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
159*67e74705SXin Li while (y <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
160*67e74705SXin Li while (y > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
161*67e74705SXin Li while (y < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
162*67e74705SXin Li
163*67e74705SXin Li while (BarD == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
164*67e74705SXin Li while (BarD != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
165*67e74705SXin Li while (BarD >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
166*67e74705SXin Li while (BarD <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
167*67e74705SXin Li while (BarD > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
168*67e74705SXin Li while (BarD <FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
169*67e74705SXin Li
170*67e74705SXin Li while (BarD == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
171*67e74705SXin Li while (BarD != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
172*67e74705SXin Li while (BarD >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
173*67e74705SXin Li while (BarD <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
174*67e74705SXin Li while (BarD < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
175*67e74705SXin Li while (BarD > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
176*67e74705SXin Li
177*67e74705SXin Li while (y == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
178*67e74705SXin Li while (y != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
179*67e74705SXin Li while (y >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
180*67e74705SXin Li while (y <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
181*67e74705SXin Li while (y > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
182*67e74705SXin Li while (y < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
183*67e74705SXin Li
184*67e74705SXin Li while (BarD == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
185*67e74705SXin Li while (BarD != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
186*67e74705SXin Li while (BarD >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
187*67e74705SXin Li while (BarD <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
188*67e74705SXin Li while (BarD > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
189*67e74705SXin Li while (BarD < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
190*67e74705SXin Li
191*67e74705SXin Li while (getBar() == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
192*67e74705SXin Li while (getBar() != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
193*67e74705SXin Li while (getBar() >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
194*67e74705SXin Li while (getBar() <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
195*67e74705SXin Li while (getBar() > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
196*67e74705SXin Li while (getBar() < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
197*67e74705SXin Li
198*67e74705SXin Li while (getBar() == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
199*67e74705SXin Li while (getBar() != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
200*67e74705SXin Li while (getBar() >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
201*67e74705SXin Li while (getBar() <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
202*67e74705SXin Li while (getBar() > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
203*67e74705SXin Li while (getBar() < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
204*67e74705SXin Li
205*67e74705SXin Li while (getBar() == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
206*67e74705SXin Li while (getBar() != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
207*67e74705SXin Li while (getBar() >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
208*67e74705SXin Li while (getBar() <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
209*67e74705SXin Li while (getBar() > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
210*67e74705SXin Li while (getBar() < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
211*67e74705SXin Li
212*67e74705SXin Li }
213