Created on 2022-09-18.00:00:00 last changed 1 week ago
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: