http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48001
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |manu at gcc dot gnu.org Summary|-Wuninitialized warning |inconsistent warning within |caught a different way for |loop always taken and |printf and ++ in loop |outside the loop --- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-03-05 21:41:16 UTC --- This is because printf has side-effects (printing) but x++ does not have any side-effects (x is unused), therefore, gcc removes x completely in the third testcase. I guess the loop is also removed completely. This is a too artificial testcase, in the sense that we do not care that x is uninitialized because it is never used for anything. We warn for the first testcase because the mechanism for detecting "is" is different from the mechanism for detecting "may be". The former happens before we remove the unused x, but the latter happens after in order to not warn for dead code. There is also the problem that GCC cannot detect that loops are taken at least once, which makes it say "maybe" when it should actually be "is". To be consistent, I would say that GCC shouldn't warn in the first testcase, or should warn as "is used" in the third testcase.