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