https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78391
Bug ID: 78391 Summary: g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized. Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lucanus81 at gmail dot com Target Milestone: --- Created attachment 40063 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40063&action=edit Minimal testcase that shows the (possible) problem. It seems like g++ (any version) doesn't warn when class members are uninitialized when no optimization is enabled (and at -O0). For -O1, -O2, -O3 we correctly get a warning (On the contrary, clang, any version, reports a warning at any optimization level). struct data { int x=w; int w=10; }; int main() { data d; return d.x; } g++ ub.cpp -Wall -Wextra -std=gnu++1z -O0 => no warning g++ ub.cpp -Wall -Wextra -std=gnu++1z -O1 => ub.cpp: In function 'int main()': ub.cpp:4:10: warning: 'd.data::w' is used uninitialized in this function [-Wuninitialized] data d; for -O2, -O3 we get exactly the same warning.