RTTI for virtual inheritance (without virtual functions)

I’ve noticed that Clang generates typeinfo for non-polymorphic types with virtual inheritance. Why is that?

My understanding is that RTTI should not be provided for non-polymorphic types.
Here is what I’ve read in ABI:


The typeinfo pointer points to the typeinfo object used for RTTI. It is always present. All entries in each of the virtual tables for a given class must point to the same typeinfo object. A correct implementation of typeinfo equality is to check pointer equality, except for pointers (directly or indirectly) to incomplete types. The typeinfo pointer is a valid pointer for polymorphic classes, i.e. those with virtual functions, and is zero for non-polymorphic classes.

So I’ve expected 0 value of typeinfo for classes without virtual functions.
In practice however both GCC and Clang generate typeinfo. Why is that?


struct VirtualBase {};

struct Derived0 : virtual VirtualBase{};
struct Derived1 : virtual VirtualBase{};
struct MostDerived : Derived0, Derived1 {};

int main()
MostDerived md;
uintptr_t **vtable = (uintptr_t **)&md;
type_info * tinfo = (type_info *)(*vtable)[-1];
cout << tinfo->name() << “\n”;
return 0;