gcc generates supruious warnings about switches not handling things which it could (or should) be easily able to deduce are impossible (e.g. assert(v!=FOO) just before the switch that gets reported for not handling FOO.
Environment: System: Linux duncan 2.6.11.10 #34 Thu May 26 11:47:48 BST 2005 i686 GNU/Linux Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc/configure --prefix=/usr --enable-shared How-To-Repeat: Compile the following fuction with -Wall. This is a contrived example of a case in a real program (where the fact was due to the impossible cases hitting an unconditional continue; statement in the first of two switches in a loop). The same lack of awareness might lead to poorer code, although I do not know the gcc internals enough to estimate by how much. BTW a problem also occurs in state machines when you get unitialised variable warnings because to reach the state that generates the warning you have to pass throigh a state that sets that variable. That might require some form of state machine detection and analysis (and might allow gcc to better optimise the state machine too :-) ---begin example program--- typedef enum { FOO, BAR, BAZ } foo_t; int foo(foo_t v) { switch(v) { case FOO: return 0; default: break; } switch(v) { case BAR: break; case BAZ: break; } return 1; } ---end example program--- -- Summary: suprious warnings about unhanled cases in switches Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dps at simpson dot demon dot co dot uk CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23577