annotation
RTTI itself is not really formal: C ++ only says what typeid and dynamic_cast , not how they are implemented. However, it is convenient to group such operations under a common name, which is RTTI.
Note that an implementation is not required to strictly obtain this information at runtime, i.e.
if ( typeid(int) == typeid(double) )
can also be determined during program evaluation, like std::is_same . int undeniably non-polymorphic (it does not have a "dynamic" type). cppreference even claims:
When applied to an expression of a polymorphic type, evaluation of the typeid expression may include runtime overhead (virtual table lookup), otherwise the typeid expression is allowed at compile time.
But this must be taken carefully.
Does this mean that type_info is part of RTTI, or is it just GCC behavior?
type_info is a class. You cannot create any object of this type - you can only through typeid .
-fno-rtti disable RTTI in GCC: you cannot use typeid and thus cannot type_info . They are very close to each other.
In conclusion, the original quote is perfectly correct:
POD types have type_info but no RTTI, and this is possible because type_info is not always RTTI.
Runtime information is available through typeid . There is nothing dynamic to consider (indeed, dynamic_cast does not make sense).
edmz
source share