PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/test/SemaCXX/warn-enum-compare.cpp

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