You are right that this is an optimisation which breaks in this case. Passing the compiler flag -fno-assume-unique-vtables will disable it.
-fno-assume-unique-vtables