The cast itself has undefined behaviour. Quoting C++17 (n4659) [expr.static.cast] 8.2.10/11:
A prvalue of type “pointer to cv1
B”, whereBis a class type, can be converted to a prvalue of type “pointer
to cv2D”, whereDis a class derived (Clause 13) fromB, if cv2 is the same cv-qualification as, or greater
cv-qualification than, cv1. … If the prvalue of
type “pointer to cv1B” points to aBthat is actually a subobject of an object of typeD, the resulting pointer
points to the enclosing object of typeD. Otherwise, the behavior is undefined.