This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

enums, switches, and warnings?


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]