https://sourceware.org/bugzilla/show_bug.cgi?id=28973
Bug ID: 28973 Summary: Improve error message for missing vtable Product: binutils Version: 2.35.2 Status: UNCONFIRMED Severity: minor Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: eyalroz1 at gmx dot com Target Milestone: --- Related GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42540 If we write the following program: ``` struct A { virtual void foo() { } }; struct B : A { void foo() override; }; int main() { B b; } ``` it compiles, but fails to link: ``` <source>:10: undefined reference to `vtable for B' ``` (see https://godbolt.org/z/Mzx3c7354) Now, the reason the vtable is missing is that the C++ ABI (for x86_64?) dictates that the vtable be defined in the object file which defines the "key function" - the first non-pure, non-inline virtual member function of the class. In this case, it's `B::foo()`. The error message GNU ld emits is not useful enough. It should let the user know _why_ the vtable is undefined - as the user her/himself is not supposed to have provided a vtable; it's something else that's the problem with what they wrote. So the message should be something like: "undefined reference to the virtual method table for class `B`. This is due to no object having defined the first virtual method in class `B` which isn't inline nor pure-virtual". or if somehow the linker can figure it out: "undefined reference to the virtual method table for class `B`, due to `B::foo()` being undefined" (Obviously, the suggested wording is just a suggestion, the point is to impart the relevant information.) -- You are receiving this mail because: You are on the CC list for the bug.