* enums, switches, and warnings?
@ 2006-11-28 17:21 darby johnston
0 siblings, 0 replies; only message in thread
From: darby johnston @ 2006-11-28 17:21 UTC (permalink / raw)
To: gcc-help
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-11-28 17:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-28 17:21 enums, switches, and warnings? darby johnston
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).