https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70403
--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Richard Biener from comment #10) > McCpId* pCpId = static_cast<McCpId*>(&newCpId); > > and it's further use. You can't use an object of McId via a pointer to > McCpId but you call > > pCpId->toString (cpIdBuf, sizeof (cpIdBuf)); > > on it. You don't even need to use it through the derived pointer, simply performing the static_cast is undefined behaviour: struct base { }; struct derived : base { }; base b; static_cast<derived*>(&b); // undefined Compiling with -fsanitize=undefined would have found that bug.