http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59500
Bug ID: 59500 Summary: Bogus maybe-unintialized warning due to optimizations Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: luto at mit dot edu I would have sworn that there was a bug open about this, but I can't find it, and this bug has been annoying me for years. Compiling this code with g++ -O2 -Wall: #ifndef __cplusplus #include <stdbool.h> #endif extern int intval(); extern bool cond(); int main() { bool valid = false; int value; if (cond()) { valid = true; value = intval(); } while (!valid || intval() < value) ; return 0; } says: trivial_uninit_warning.cc: In function ‘int main()’: trivial_uninit_warning.cc:18:17: warning: ‘value’ may be used uninitialized in this function [-Wmaybe-uninitialized] while (!valid || intval() < value) Oddly, compiling exactly the same code in C (instead of C++) does not warn. This seems quite sensitive to exactly what the code is doing. IIRC the issue is that the "load" of value is moved ahead of the check of valid by the optimizer (which is entirely valid), but then that load appears to access an uninitialized value and warns.