Talk:Run-time type information

message: *I vote to keep the entry separate. I believe that the theme allows for a more comprehensive text, and if it is merged, it would probably remain as it is.
*oppose Nereocystis 14:54, 7 October 2005 (UTC)
thread_title: Merging with [[datatype]]

message: Provided code example won't compile with g++ (4.0.2). Compilation produces "source type is not polymorphic" error. Adding virtual destructor to the base class solves the problem.--Iwasz 21:59, 21 March 2006 (UTC)
replies: text: It compiles fine as of today with a recent g++ and clang++. Mlkj (talk) 22:34, 31 December 2015 (UTC)
thread_title:  Code example 

message: Currently, the article states:
*In programming, RTTI [...] means keeping information about an object's data type in memory at runtime
Isn't it more correct to say:
*In programming, RTTI [...] means keeping information about an entity's data type in memory at runtime
as runtime information can be kept for simple data types such as integers, too? --Abdull (talk) 12:04, 9 February 2008 (UTC)
replies: text: The variable article says variable has as synonyms object and identifier. Yet, I think there is the possibility of confusion with OOP objects. --Abdull (talk) 12:09, 9 February 2008 (UTC)
thread_title:  Only objects/classes? 

message: Delphi has had RTTI since the very beginning, and it's integrated into the language and used throughout the runtime, unlike C++ where it was bolted on after the fact and is a special option that has to be enabled.  —Preceding unsigned comment added by 69.46.35.146 (talk) 21:14, 22 April 2009 (UTC)
replies: text: If RTTI is use also in other languages than C++, there should be parallel code examples wherever C++ code appears. Sae1962 (talk) 08:29, 26 January 2011 (UTC)

text: The article used to be more general in its wording. This was changed by an anonymous editor in 2008, I think (see ). – Tea2min (talk) 10:53, 19 July 2019 (UTC)
thread_title:  Why is this identified as a C++ thing? 

message: Run-time type information in C++ is only available for polymorphic types. Please see [expr.dynamic.cast] and [expr.typeid] in the C++20 standard. For example, an attempt to down-cast a pointer to an instance of a non-polymorphic class A down to a pointer to an instance of a non-polymorphic cass B derived from A is ill-formed:
    class A {};
    class B : public A {};
    
    int main()
    {
        A* a = new B;
        B* b = dynamic_cast<B*>(a); // ill-formed!
    }
An up-cast would compile and would work as expected, using only static information.
Similarly, [expr.typeid] says: "When typeid is applied to an expression other than a glvalue of a polymorphic class type, the result refers to a std::type_info object representing the static type of the expression." I.e., it does compile, but the result does not (and in fact cannot) represent the dynamic type of the expression. – Tea2min (talk) 19:03, 14 July 2021 (UTC)
replies: text: Thank you, and sorry for the undue revert. You are correct that actual RTTI will only be available for polymorphic types, regardless of typeid being defined or not. BernardoSulzbach (talk) 20:06, 14 July 2021 (UTC)
thread_title:  RTTI in C++ is only available for polymorphic types