This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: No definition of virtual function, omits inline and virtualtable
- To: Peter Osterlund <peter dot osterlund at mailbox dot swipnet dot se>
- Subject: Re: No definition of virtual function, omits inline and virtualtable
- From: "James F. Carter" <jimc at math dot ucla dot edu>
- Date: Wed, 27 Sep 2000 09:18:07 -0700 (PDT)
- cc: gcc-bugs at gcc dot gnu dot org
But the point is, that compilation unit was botched. As you say, the
program as a whole was malformed, and could not have executed (at best
getting an undefined symbol at link time), but the missing virtual function
*could* have been defined in a different compilation unit and linked
in. That should be legal, but no inline bodies or virtual table would have
been generated.
It was this exact situation that clued me in to the bug. I never saw the
linker try to find the (incorrectly undefined) virtual function, which is
why it took so long to figure out what was triggering the bug.
James F. Carter Voice 310 825 2897 FAX 310 206 6673
UCLA-Mathnet; 6115 MSA; 405 Hilgard Ave.; Los Angeles, CA, USA 90095-1555
Internet: jimc@math.ucla.edu (finger for PGP key)
UUCP:...!{ucsd,ames,ncar,gatech,purdue,rutgers,decvax,uunet}!math.ucla.edu!jimc
On 24 Sep 2000, Peter Osterlund wrote:
> Jim Carter <jimc@math.ucla.edu> writes:
>
> > /* bug03.C -- No definition of virtual function, omits inline and virtual table
>
> The C++ (draft) standard says
>
> A virtual function declared in a class shall be defined, or
> declared pure (_class.abstract_) in that class, or both; but
> no diagnostic is required (_basic.def.odr_).
>
> so your program is ill formed. T::twiddle() is never defined. You
> should be lucky you got an error message at all. The standard also
> allows the compiler to create a program that crashes mysteriously at
> run-time.
>
> --
> Peter Österlund Email: peter.osterlund@mailbox.swipnet.se
> Sköndalsvägen 35 f90-pos@nada.kth.se
> S-128 66 Sköndal Home page: http://home1.swipnet.se/~w-15919
> Sweden Phone: +46 8 942647
>