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

2024-12-19


2740. Too many objects have constexpr-unknown type

Section: 7.7  [expr.const]     Status: open     Submitter: Richard Smith     Date: 2023-02-10

Consider:

  struct A {
    A();
    virtual constexpr int f() { return 1; }
  };
  struct B : A {
    virtual constexpr int f() { return 2; }
  };
  B b; // not constexpr
  auto &id = typeid(b); // error, not constant

The example had been valid, but became invalid under P2280. The same happened for dynamic_cast. Furthermore, P2280 seems to be missing a change for static_cast from base to derived and for pointer-to-member access expressions, which both depend on the dynamic type and have historically been required to work.

Maybe a better rule would be that objects (not references) whose lifetime did not begin within E are treated as having a dynamic type that is their declared type.