------- Comment #5 from manu at gcc dot gnu dot org 2010-06-17 08:37 ------- (In reply to comment #4) > It seems that optimizing is what's causing the problem: the example compiles > fine with -O0, but not -On>=1. It also compiles fine when the case values are > consecutive, which seems telling. My first guess would be to take a look at > what optimizations are being done to switch statements that have > non-consecutive-valued cases as opposed to those that have consecutive values. >
Wuninitialized does not detect as many cases with -O0 than with higher optimizations. When the cases are consecutive, VRP kicks in and simplifies the switch. You can check what is going on using -fdump-tree-all-lineno and inspecting the dumps. n(D) means the uninitialized value of n. When that is removed, then Wuninitialized will not warn. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44547