https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63164
--- Comment #13 from Thomas de Bock <tdebock at DRWUK dot com> --- (In reply to Jakub Jelinek from comment #12) > I'd think it should just optimize __dynamic_cast to > std::type_info::operator== in that case (if that is available) or, if not > (i.e. <typeinfo> not included) to > if (__name == __arg.__name) > return true; > return __name[0] != '*' && __builtin_strcmp (__name, __arg.__name) == 0; > or so. I think that would be insufficient, since from looking at the definition: type_info::operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT { if (std::__is_constant_evaluated()) return this == &__arg; if (__name == __arg.__name) return true; #if !__GXX_TYPEINFO_EQUALITY_INLINE // ABI requires comparisons to be non-inline. return __equal(__arg); #elif !__GXX_MERGED_TYPEINFO_NAMES // Need to do string comparison. return __name[0] != '*' && __builtin_strcmp (__name, __arg.name()) == 0; #else return false; #endif besides compile-time evaluation, it always compares the type names, which still leaves much room for optimization.