When and why is an std::__non_rtti_object exception generated?

I ran a test based on your pseudo-code and it works. So if RTTI is truly enabled in your build configuration, then it must be another problem that isn't captured in what you posted.


https://learn.microsoft.com/en-us/cpp/cpp/typeid-operator?view=vs-2019 has info on __non_rtti_object_exception.

From MSDN:

If the pointer does not point to a valid object, a __non_rtti_objectexception is thrown, indicating an attempt to analyze the RTTI that triggered a fault (like access violation), because the object is somehow invalid (bad pointer or the code wasn't compiled with /GR).