Title
Too many objects have constexpr-unknown type
Status
open
Section
7.7 [expr.const]
Submitter
Richard Smith

Created on 2023-02-10.00:00:00 last changed 14 months ago

Messages

Date: 2023-02-10.00:00:00

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.

History
Date User Action Args
2023-02-10 00:00:00admincreate