We have a large code base in C++ and after a smallish refactor (one class added and some related methods rewritten), we started getting linker errors on GCC 3 & 4. The linker errors were specifically "missing references to non-virtual thunks" in small sample programs that subclassed classes in our large SDK.
Searching the web didn't give many hints beyond some old GCC bugs that seem to have been resolved.
The attributes of the problem seem to be:
- GCC 3.4.6 & 4.3.3 optimizing with
-O2
- Multiple inheritance, including occasional virtual inheritance.
- Changing the inheritance order from, say,
class Foo: public A, public B {}
to
class Foo: public B, public A {}
on the classes that are missing the thunks "fixes" the problem.
The virtual inheritance only appears in a single, very-commonly used base class for reference counting. I have verified that every usage of this class really is virtual public, and not just public inheritance by accident.
Obviously fiddling with the inheritance order is not really solving the problem. What else could it be?