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

2024-03-20


2633. typeid of constexpr-unknown dynamic type

Section: 7.7  [expr.const]     Status: open     Submitter: Jim X     Date: 2022-09-18

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: