1 // RUN: %clang_cc1 %s -fsyntax-only -verify 2 3 enum Foo { FooA, FooB, FooC }; 4 enum Bar { BarD, BarE, BarF }; 5 enum { AnonAA = 42, AnonAB = 43 }; 6 enum { AnonBA = 44, AnonBB = 45 }; 7 enum { Anon1, Anon2, Anon3 }; 8 typedef enum { TD1, TD2 } TD; 9 10 namespace name1 { 11 enum Foo {F1, F2, F3}; 12 enum Baz {B1, B2, B3}; 13 } 14 15 namespace name2 { 16 enum Baz {B1, B2, B3}; 17 } 18 19 using name1::Baz; 20 using name1::B1; 21 using name2::B2; 22 typedef name1::Foo oneFoo; 23 typedef name1::Foo twoFoo; 24 Foo getFoo(); 25 Bar getBar(); 26 27 void test () { 28 Foo x = FooA; 29 Bar y = BarD; 30 Baz z = name1::B3; 31 name1::Foo a; 32 oneFoo b; 33 twoFoo c; 34 TD td; 35 36 while (x == FooA); 37 while (y == BarD); 38 while (a == name1::F1); 39 while (z == name1::B2); 40 while (a == b); 41 while (a == c); 42 while (b == c); 43 while (B1 == name1::B2); 44 while (B2 == name2::B1); 45 while (x == AnonAA); // expected-warning {{comparison of constant 'AnonAA' (42) with expression of type 'Foo' is always false}} 46 while (AnonBB == y); // expected-warning {{comparison of constant 'AnonBB' (45) with expression of type 'Bar' is always false}} 47 while (AnonAA == AnonAB); 48 while (AnonAB == AnonBA); 49 while (AnonBB == AnonAA); 50 51 while ((x) == FooA); 52 while ((y) == BarD); 53 while ((a) == name1::F1); 54 while (z == (name1::B2)); 55 while (a == (b)); 56 while (a == (c)); 57 while ((b) == (c)); 58 while ((B1) == (name1::B2)); 59 while ((B2) == (name2::B1)); 60 61 while (((x)) == FooA); 62 while ((y) == (BarD)); 63 while ((a) == (name1::F1)); 64 while (z == (name1::B2)); 65 while ((a) == ((((b))))); 66 while (((a)) == (c)); 67 while ((b) == (((c)))); 68 while ((((((B1))))) == (((name1::B2)))); 69 while (B2 == ((((((name2::B1))))))); 70 71 while (td == Anon1); 72 while (td == AnonAA); // expected-warning {{comparison of constant 'AnonAA' (42) with expression of type 'TD' is always false}} 73 74 while (B1 == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 75 while (name1::B2 == name2::B3); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 76 while (z == name2::B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 77 78 while (((((B1)))) == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 79 while (name1::B2 == (name2::B3)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 80 while (z == ((((name2::B2))))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 81 82 while ((((B1))) == (((B2)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 83 while ((name1::B2) == (((name2::B3)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 84 while ((((z))) == (name2::B2)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}} 85 86 while (x == a); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'name1::Foo')}} 87 while (x == b); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'oneFoo' (aka 'name1::Foo'))}} 88 while (x == c); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'twoFoo' (aka 'name1::Foo'))}} 89 90 while (x == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 91 while (x != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 92 while (x >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 93 while (x <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 94 while (x > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 95 while (x < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 96 97 while (FooB == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 98 while (FooB != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 99 while (FooB >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 100 while (FooB <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 101 while (FooB > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 102 while (FooB < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 103 104 while (FooB == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 105 while (FooB != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 106 while (FooB >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 107 while (FooB <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 108 while (FooB > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 109 while (FooB < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 110 111 while (x == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 112 while (x != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 113 while (x >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 114 while (x <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 115 while (x > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 116 while (x < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 117 118 while (getFoo() == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 119 while (getFoo() != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 120 while (getFoo() >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 121 while (getFoo() <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 122 while (getFoo() > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 123 while (getFoo() < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 124 125 while (getFoo() == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 126 while (getFoo() != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 127 while (getFoo() >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 128 while (getFoo() <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 129 while (getFoo() > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 130 while (getFoo() < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 131 132 while (getFoo() == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 133 while (getFoo() != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 134 while (getFoo() >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 135 while (getFoo() <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 136 while (getFoo() > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 137 while (getFoo() < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 138 139 while (FooB == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 140 while (FooB != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 141 while (FooB >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 142 while (FooB <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 143 while (FooB > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 144 while (FooB < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 145 146 while (x == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 147 while (x != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 148 while (x >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 149 while (x <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 150 while (x > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 151 while (x < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}} 152 153 154 155 while (y == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 156 while (y != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 157 while (y >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 158 while (y <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 159 while (y > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 160 while (y < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 161 162 while (y == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 163 while (y != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 164 while (y >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 165 while (y <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 166 while (y > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 167 while (y < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 168 169 while (BarD == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 170 while (BarD != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 171 while (BarD >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 172 while (BarD <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 173 while (BarD > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 174 while (BarD <FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 175 176 while (BarD == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 177 while (BarD != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 178 while (BarD >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 179 while (BarD <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 180 while (BarD < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 181 while (BarD > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 182 183 while (y == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 184 while (y != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 185 while (y >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 186 while (y <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 187 while (y > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 188 while (y < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 189 190 while (BarD == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 191 while (BarD != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 192 while (BarD >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 193 while (BarD <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 194 while (BarD > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 195 while (BarD < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 196 197 while (getBar() == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 198 while (getBar() != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 199 while (getBar() >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 200 while (getBar() <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 201 while (getBar() > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 202 while (getBar() < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 203 204 while (getBar() == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 205 while (getBar() != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 206 while (getBar() >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 207 while (getBar() <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 208 while (getBar() > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 209 while (getBar() < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 210 211 while (getBar() == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 212 while (getBar() != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 213 while (getBar() >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 214 while (getBar() <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 215 while (getBar() > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 216 while (getBar() < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}} 217 218 while (td == FooA); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'Foo')}} 219 while (td == BarD); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'Bar')}} 220 while (name1::F1 == td); // expected-warning {{comparison of two values with different enumeration types ('name1::Foo' and 'TD')}} 221 while (name2::B1 == td); // expected-warning {{comparison of two values with different enumeration types ('name2::Baz' and 'TD')}} 222 while (td == a); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'name1::Foo')}} 223 while (td == b); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'oneFoo' (aka 'name1::Foo'))}} 224 while (td == c); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'twoFoo' (aka 'name1::Foo'))}} 225 while (td == x); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'Foo')}} 226 while (td == y); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'Bar')}} 227 while (td == z); // expected-warning {{comparison of two values with different enumeration types ('TD' and 'name1::Baz')}} 228 229 while (a == TD1); // expected-warning {{comparison of two values with different enumeration types ('name1::Foo' and 'TD')}} 230 while (b == TD2); // expected-warning {{comparison of two values with different enumeration types ('oneFoo' (aka 'name1::Foo') and 'TD')}} 231 while (c == TD1); // expected-warning {{comparison of two values with different enumeration types ('twoFoo' (aka 'name1::Foo') and 'TD')}} 232 while (x == TD2); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'TD')}} 233 while (y == TD1); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'TD')}} 234 while (z == TD2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'TD')}} 235 236 switch (a) { 237 case name1::F1: break; 238 case name1::F3: break; 239 case name2::B2: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('name1::Foo' and 'name2::Baz')}} 240 } 241 242 switch (x) { 243 case FooB: break; 244 case FooC: break; 245 case BarD: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('Foo' and 'Bar')}} 246 } 247 248 switch(getBar()) { 249 case BarE: break; 250 case BarF: break; 251 case FooA: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('Bar' and 'Foo')}} 252 } 253 254 switch(x) { 255 case AnonAA: break; // expected-warning {{case value not in enumerated type 'Foo'}} 256 case FooA: break; 257 case FooB: break; 258 case FooC: break; 259 } 260 261 switch (td) { 262 case TD1: break; 263 case FooB: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('TD' and 'Foo')}} 264 case BarF: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('TD' and 'Bar')}} 265 // expected-warning@-1 {{case value not in enumerated type 'TD'}} 266 case AnonAA: break; // expected-warning {{case value not in enumerated type 'TD'}} 267 } 268 269 switch (td) { 270 case Anon1: break; 271 case TD2: break; 272 } 273 274 switch (a) { 275 case TD1: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('name1::Foo' and 'TD')}} 276 case TD2: break; // expected-warning {{comparison of two values with different enumeration types in switch statement ('name1::Foo' and 'TD')}} 277 case name1::F3: break; 278 } 279 } 280