summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/warn-enum-compare.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaCXX/warn-enum-compare.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaCXX/warn-enum-compare.cpp')
-rw-r--r--clang/test/SemaCXX/warn-enum-compare.cpp212
1 files changed, 212 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-enum-compare.cpp b/clang/test/SemaCXX/warn-enum-compare.cpp
new file mode 100644
index 0000000..52639e7
--- /dev/null
+++ b/clang/test/SemaCXX/warn-enum-compare.cpp
@@ -0,0 +1,212 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+enum Foo { FooA, FooB, FooC };
+enum Bar { BarD, BarE, BarF };
+enum { AnonAA = 42, AnonAB = 43 };
+enum { AnonBA = 44, AnonBB = 45 };
+
+namespace name1 {
+ enum Foo {F1, F2, F3};
+ enum Baz {B1, B2, B3};
+}
+
+namespace name2 {
+ enum Baz {B1, B2, B3};
+}
+
+using name1::Baz;
+using name1::B1;
+using name2::B2;
+typedef name1::Foo oneFoo;
+typedef name1::Foo twoFoo;
+Foo getFoo();
+Bar getBar();
+
+void test () {
+ Foo x = FooA;
+ Bar y = BarD;
+ Baz z = name1::B3;
+ name1::Foo a;
+ oneFoo b;
+ twoFoo c;
+
+ while (x == FooA);
+ while (y == BarD);
+ while (a == name1::F1);
+ while (z == name1::B2);
+ while (a == b);
+ while (a == c);
+ while (b == c);
+ while (B1 == name1::B2);
+ while (B2 == name2::B1);
+ while (x == AnonAA);
+ while (AnonBB == y);
+ while (AnonAA == AnonAB);
+ while (AnonAB == AnonBA);
+ while (AnonBB == AnonAA);
+
+ while ((x) == FooA);
+ while ((y) == BarD);
+ while ((a) == name1::F1);
+ while (z == (name1::B2));
+ while (a == (b));
+ while (a == (c));
+ while ((b) == (c));
+ while ((B1) == (name1::B2));
+ while ((B2) == (name2::B1));
+
+ while (((x)) == FooA);
+ while ((y) == (BarD));
+ while ((a) == (name1::F1));
+ while (z == (name1::B2));
+ while ((a) == ((((b)))));
+ while (((a)) == (c));
+ while ((b) == (((c))));
+ while ((((((B1))))) == (((name1::B2))));
+ while (B2 == ((((((name2::B1)))))));
+
+ while (B1 == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+ while (name1::B2 == name2::B3); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+ while (z == name2::B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+
+ while (((((B1)))) == B2); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+ while (name1::B2 == (name2::B3)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+ while (z == ((((name2::B2))))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+
+ while ((((B1))) == (((B2)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+ while ((name1::B2) == (((name2::B3)))); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+ while ((((z))) == (name2::B2)); // expected-warning {{comparison of two values with different enumeration types ('name1::Baz' and 'name2::Baz')}}
+
+ while (x == a); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'name1::Foo')}}
+ while (x == b); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'oneFoo' (aka 'name1::Foo'))}}
+ while (x == c); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'twoFoo' (aka 'name1::Foo'))}}
+
+ while (x == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (FooB == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (FooB == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (x == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (getFoo() == y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() != y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() >= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() <= y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() > y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() < y); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (getFoo() == BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() != BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() >= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() <= BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() > BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() < BarD); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (getFoo() == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (getFoo() < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (FooB == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (FooB < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+ while (x == getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x != getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x >= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x <= getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x > getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+ while (x < getBar()); // expected-warning {{comparison of two values with different enumeration types ('Foo' and 'Bar')}}
+
+
+
+ while (y == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (y == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (BarD == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD <FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (BarD == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (y == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (y < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (BarD == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (BarD < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (getBar() == getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() != getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() >= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() <= getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() > getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() < getFoo()); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (getBar() == FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() != FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() >= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() <= FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() > FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() < FooB); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+ while (getBar() == x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() != x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() >= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() <= x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() > x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+ while (getBar() < x); // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
+
+}