Title
typeid of constexpr-unknown dynamic type
Status
open
Section
7.7 [expr.const]
Submitter
Jim X

Created on 2022-09-18.00:00:00 last changed 27 months ago

Messages

Date: 2022-09-18.00:00:00

Consider the example in 7.7 [expr.const] paragraph 7:

extern Swim dc;
constexpr auto& sandeno  = typeid(dc);     // OK, can only be typeid(Swim)

The comment in the example seems not to be backed by normative text. In particular, the dynamic type of dc is constexpr-unknown per 7.7 [expr.const] paragraph 7:

During the evaluation of an expression E as a core constant expression, all id-expressions and uses of *this that refer to an object or reference whose lifetime did not begin with the evaluation of E are treated as referring to a specific instance of that object or reference whose lifetime and that of all subobjects (including all union members) includes the entire constant evaluation. For such an object that is not usable in constant expressions, the dynamic type of the object is constexpr-unknown. ...

Thus, typeid(dc) is not a core constant expression per 7.7 [expr.const] bullet 5.26:

  • a dynamic_cast (7.6.1.7 [expr.dynamic.cast]) or typeid (7.6.1.8 [expr.typeid]) expression on a glvalue that refers to an object whose dynamic type is constexpr-unknown or that would throw an exception;
History
Date User Action Args
2022-09-18 00:00:00admincreate