This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


2512. typeid and incomplete class types

Section: 7.6.1.8  [expr.typeid]     Status: NAD     Submitter: Jens Maurer     Date: 2021-08-19

According to 7.6.1.8 [expr.typeid] paragraphs 2-3,

When typeid is applied to a glvalue whose type is a polymorphic class type (11.7.3 [class.virtual]), the result refers to a std::type_info object representing the type of the most derived object (6.7.2 [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_info object representing the static type of the expression.

The status of a glvalue of incomplete class type is not clear from this specification. Since it is not known whether an incomplete class type is polymorphic or not, the existing wording could be read either as giving that case undefined behavior or as falling into paragraph 3 and always returning the static type.

The wording for dynamic_cast requires class types to be complete, as does paragraph 4, describing typeid applied to a type-id.

Rationale (December, 2021):

The change was already applied via the editorial review process, with approval from CWG at the 2021-08-24 teleconference.