https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100126
Bug ID: 100126 Summary: missing -Wuninitialized using a trivial member of class with another nontrivial member Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Reading an uninitialized trivial member of a struct that contains a member of a type with a user-defined (or similar) ctor is not diagnosed. The reason is that the call to the ctor is (exceedingly) conservatively assumed to store into the other members of the enclosing struct. $ gcc -O1 -S -Wall -fdump-tree-uninit=/dev/stdout t.C struct A { char *p; A (); }; struct B { int i; A a; }; void f () { B b; __builtin_printf ("%d\n", b.i); // missing -Wuninitialized } ;; Function f (_Z1fv, funcdef_no=0, decl_uid=2365, cgraph_uid=4, symbol_order=3) void f () { struct B b; int _1; <bb 2> [local count: 1073741824]: A::A (&b.a); <<< assumed to set b.i _1 = b.i; __builtin_printf ("%d\n", _1); <<< missing -Wuninitialized b ={v} {CLOBBER}; return; } This isn't C++ specific. The same limitation affects C: struct A { char *p; }; void init (struct A *); struct B { int i; struct A a; }; void f () { struct B b; init (&b.a); __builtin_printf ("%d\n", b.i); }