https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93096
Bug ID: 93096 Summary: detect [class.cdtor]/6 UB in constexpr dynamic_cast Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mpolacek at gcc dot gnu.org Target Milestone: --- We should detect the UB here: struct V { virtual void f(); }; struct A : V { }; struct B : V { constexpr B(V*, A*); }; struct D : A, B { constexpr D() : B((A*)this, this) { } }; constexpr B::B(V* v, A* a) { // undefined behavior, a has type A*, A not a base of B dynamic_cast<B*>(a); } constexpr D d; but currently we don't. This is <http://eel.is/c++draft/class.cdtor#6.sentence-3>. See <https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01521.html> for another testcase and possible approaches how to handle this.