This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: undefined virtual table: a misleading error message in egcs-2.91.66
- To: akale at veritas dot com
- Subject: Re: undefined virtual table: a misleading error message in egcs-2.91.66
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Mon, 15 May 2000 10:21:29 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- References: <00051513124400.08668@fermat.vxindia.veritas.com>
> A program given below shows the problem. If defines a class foo with a pure
> virtual function fun.
Thanks for your bug report. This is a known problem.
> Compiler sems to generate virtual table noly when a virtual function
> is implemented. Shouldn't virtual table be generated whenever it is
> referenced, e.g in constructor?
No. It is an optimization to only emit virtual tables, RTTI, and
out-of-line copies of inline virtual functions together with the first
non-pure non-inline virtual function. Using this optimzation gives
quite some savings in executable size.
It is also a legal optimization: The standard requires that *all*
virtual functions of a class must be defined, whether they are used or
not. In particular, the first such function must be defined, so the
compiler can trust that it will see a definition sometime.
> Can this be fixed?
Hardly. The error is detected by the linker, and the linker has no
knowledge what the first virtual function was. One possible scheme
could work like this:
- the compiler emits a hint to the linker telling it what the first
virtual function was
- when the linker sees a missing virtual table symbol, it checks whether
it also has a hint, and then prints an appropriate message
Unfortunately, this is very difficult to implement, especially on
systems where the linker is supplied by the OS vendor.
Regards,
Martin