extern void foo(int); void test() { int change_y, y , new_y; { int save_y; if (change_y) save_y = y, y = new_y; if (change_y) y = save_y; } foo(y); }
int main() { test(); return 0; } If I compile this code with "-Wuninitialized -O1" or "-Wuninitialized -O2" with the MinGW 3.4.2 GCC I got those warnings: test2.cpp: In function `void test()': test2.cpp:5: warning: 'change_y' might be used uninitialized in this function test2.cpp:5: warning: 'y' might be used uninitialized in this function But I compile it with "-Wuninitialized -O3" I get this: test2.cpp: In function `void test()': test2.cpp:5: warning: 'change_y' might be used uninitialized in this function test2.cpp:5: warning: 'y' might be used uninitialized in this function test2.cpp: In function `int main()': test2.cpp:5: warning: 'change_y' might be used uninitialized in this function test2.cpp:5: warning: 'y' might be used uninitialized in this function Which is obviously two surplus warnings and those two warnings also referencing to the wrong function. But when I comment the foo() call, then I get no warning at all, but I don't know how the optimizations of GCC work, so it might be, because all the vars are removed, because they aren't used at all and are "dead code". MinGW GCC 3.3.3 and a linux GCC 3.2 also behaves the same. -- Summary: surplus -Wuninitialized warnings Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: oliverst at online dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19763