[Bug c++/103600] Cannot use typeid result in constant expressions

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 7 13:47:30 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103600

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The new definition of operator== will be something like:

#if __GXX_TYPEINFO_EQUALITY_INLINE || __cplusplus > 202002L
  _GLIBCXX23_CONSTEXPR inline bool
  type_info::operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT
  {
    if (__name == __arg.__name)
      return true;

    if (!std::__is_constant_evaluated())
      return false;

#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
  }
# endif


i.e. no strcmp for the constant evaluation case. During constant evaluation I
think we only need to handle types that are completely defined in the current
TU, so we can ignore aliasing of _ZTi symbols, and we can ignore the problem of
non-unique std::type_info objects. Within the TU they will be unique.


More information about the Gcc-bugs mailing list