enums, switches, and warnings?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Just ran across a warning (or actually lack-of) that
surprised me a bit; example code:

enum A { A0, A1, A2 };
enum B { B0, B1, B2, B3 };

int main(int, char **)
{
  A a = A0;
  switch (a) {
    case A0: break;
    case A1: break;
    //case B2: break;
    //case B3: break;
  }
  
  return 0;
}

Compiling gives:

warning: enumeration value ?A2? not handled in switch

But remove the first comment (B2) and the warning goes
away. Then removing the second comment (B3), gives:

warning: case value ?3? not in enumerated type ?A?

I know that enums are automatically converted to ints,
but shouldn't there be a warning that you're mixing
enum types?

This is using:

gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

Thanks, Darby

PS. I would never actually write something like this,
it's from a bug I found in my code.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux