Fix compatibility issue for std::bad_cast