https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103989
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- The reason we warn is that at -Og we don't optimize away the dead code. In uninit2 we have: MEM[(struct _Optional_payload_base *)&D.34851]._M_engaged = 0; ... _27 = MEM[(const struct _Optional_payload_base &)&D.34851]._M_engaged; if (_27 != 0) goto <bb 3>; [33.00%] else goto <bb 10>; [67.00%] <bb 10> [local count: 719407024]: goto <bb 9>; [100.00%] <bb 3> [local count: 354334800]: MEM[(struct __as_base &)&b] ={v} {CLOBBER}; MEM[(struct shared_ptr *)&b] ={v} {CLOBBER}; MEM[(struct __shared_ptr *)&b] ={v} {CLOBBER}; _30 = MEM[(const struct __shared_ptr &)&D.34851]._M_ptr; MEM[(struct __shared_ptr *)&b]._M_ptr = _30; MEM[(struct __shared_count *)&b + 8B] ={v} {CLOBBER}; _31 = MEM[(const struct __shared_count &)&D.34851 + 8]._M_pi; MEM[(struct __shared_count *)&b + 8B]._M_pi = _31; and we haven't figured out that bb 3 is all dead, because we store into _M_engaged 0 and bb 3 is done only if _M_engaged is non-zero. -Og runs fre1, but that is too early, fre1 sees MEM[(struct _Optional_payload_base *)&D.34851]._M_engaged = 0; D.35431 ={v} {CLOBBER}; b ={v} {CLOBBER}; MEM[(struct optional *)&b] ={v} {CLOBBER}; std::_Optional_base<A, false, false>::_Optional_base (&MEM[(struct optional *)&b].D.34640, &D.34851.D.34640); and _Optional_base isn't inlined there. And -Og doesn't do any FRE or PRE after inlining, unlike e.g. -O1 which has fre3 very soon after inlining. -Og doesn't even do forwprop after inlining.