[Bug c++/96283] "undefined vtable" error should indicate which members are missing

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jul 22 13:51:12 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96283

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Eyal Rozenberg from comment #0)
> While this is true, it is a bit confusing. But even supposing I looked up
> what this error means and realized what was going on, I would still need to
> go over all the methods of one or two of the classes to find the one that's
> missing its implementation. In this simple example that's not so difficult,
> but sometimes it's quite the nuisance.

But you don't need to go over all of them at all. The error happens because the
key function is not defined, so that's the only one that you need to define in
order to produce a vtable.

See
https://gcc.gnu.org/wiki/VerboseDiagnostics#undefined_reference_to_vtable_for_X

> I'm assuming the compiler provides the linker with enough information to
> realize which virtual methods' implementations are missing, so that the
> linker can finally print an error message which methods are still missing
> after it has run.

The linker doesn't know anything about virtual functions. It doesn't even know
anything about a vtable, it just knows there are undefined references to
symbols called _ZTV4Base and _ZTV3foo, so it prints those out (after demangling
them).

> In this specific case, the linker should complain about vmethod() missing
> its definition.

Th linker is not part of GCC though, so if you want changes to the linker, this
is the wrong place to ask for it.


More information about the Gcc-bugs mailing list