This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
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;