static_cast from the base class to the derived class is UB, as is static_cast between custom layout classes (those that have virtual or non-public members or bases or multiple inheritance). So that the code above is correct, you need public inheritance
struct base : public root{}; struct derive : public base{};
and you can only static_cast from derive to base or root , and from base to root , and not in the other direction.
Given the usual GCC semantics, it probably "should" accept your code, but it also makes sense that this does not happen because it relies on non-standard behavior.
Ray hamel
source share