https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63164
--- Comment #19 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jason Merrill from comment #17) > As I commented at > > https://inbox.sourceware.org/gcc-patches/75ff8af8-af03-42fa-b68b- > e6c16a34c...@redhat.com/ > > we could optimize the dynamic_cast to type_info::operator== instead of > vtable comparison. That is what I was suggesting in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63164#c12 Just I think one can use dynamic_cast even without including <typeinfo>. So, one possibility is only optimize if <typeinfo> has been included, another is trying to do what it would otherwise do (the safer variant thereof) inline; most likely not for -Os because it will be larger, maybe in both cases. I think even doing the slowest variant of operator== will be still much faster than dynamic_cast.