c++: Fix tsubst ICE with invalid static_cast [PR95728]