https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83367
Martin Liška <marxin at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED CC| |marxin at gcc dot gnu.org Resolution|--- |INVALID --- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> --- First note that in cTest::cTest you take pointer this and register it to a cTestList. That requires that all cTest instances will have defined storage and will not be out of scope. However in this case static variables 'a' and 'ab' are defined static in scope of Tests.cpp and as there's no reference to these variables, compiler makes optimization and removes these variables. Then static initializer looks as follows: (static initializers for Tests.cpp) () { struct cTestRegister D.2548; struct cTestRegister D.2547; <bb 2> [100.00%]: MEM[(struct &)&D.2548] ={v} {CLOBBER}; D.2548.m_pchRoot = 0B; D.2548.m_pchName = "a"; cTestRegister::operator+ (&D.2548, _FUN); [return slot optimization] D.2548 ={v} {CLOBBER}; MEM[(struct &)&D.2547] ={v} {CLOBBER}; D.2547.m_pchRoot = "a"; D.2547.m_pchName = "b"; cTestRegister::operator+ (&D.2547, _FUN); [return slot optimization] D.2547 ={v} {CLOBBER}; return; } Then it's quite clear how the bad thinks happen.