Search code examples
c++typeinfo

Why is type_info::name() unspecified?


I'm fully aware that the return value of std::type_info::name() is implementation-defined.

From the C++ standard (ISO/IEC 14882:2003 §18.5.1.7):

Returns: an implementation-defined NTBS.

My question is: why? Wouldn't this member function be much more useful if the standard dictated what the return value should be?


Solution

  • Basically, if an implementation decides that they can't or doesn't want to support RTTI, they can just return "";. If the standard forced it to return something, they'd possibly kill any ability to have a compliant compiler for an environment where the resources for RTTI don't exist or want to be disabled (a microchip, for example.)

    And let's not forget we don't want to force an ABI/name-mangling scheme on any compilers.

    This follows the C++ philosophy "You don't pay for things you don't need."