[expr.typeid] (original) (raw)

7 Expressions [expr]

7.6 Compound expressions [expr.compound]

7.6.1 Postfix expressions [expr.post]

7.6.1.8 Type identification [expr.typeid]

The result of a typeid expression is an lvalue of static typeconst std​::​type_info ([type.info]) and dynamic type const std​::​type_info or const name where name is animplementation-defined class publicly derived fromstd​::​type_info which preserves the behavior described in [type.info].52

The lifetime of the object referred to by the lvalue extends to the end of the program.

Whether or not the destructor is called for thestd​::​type_info object at the end of the program is unspecified.

If the type of the expression or type-id operand is a (possibly cv-qualified) class type or a reference to (possibly cv-qualified) class type, that class shall be completely defined.

When typeid is applied to a glvalue whose type is a polymorphic class type ([class.virtual]), the result refers to astd​::​type_info object representing the type of the most derived object ([intro.object]) (that is, the dynamic type) to which the glvalue refers.

When typeid is applied to an expression other than a glvalue of a polymorphic class type, the result refers to a std​::​type_infoobject representing the static type of the expression.

When typeid is applied to a type-id, the result refers to a std​::​type_info object representing the type of thetype-id.

If the type of the type-id is a reference to a possibly cv-qualified type, the result of thetypeid expression refers to a std​::​type_info object representing the cv-unqualified referenced type.

If the type of the expression or type-id is a cv-qualified type, the result of the typeid expression refers to a std​::​type_info object representing the cv-unqualified type.

[Example 1: class D { }; D d1;const D d2;typeid(d1) == typeid(d2); typeid(D) == typeid(const D); typeid(D) == typeid(d2); typeid(D) == typeid(const D&); — _end example_]

[Note 3:

Subclause [class.cdtor] describes the behavior of typeidapplied to an object under construction or destruction.

— _end note_]