This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: collect2 / ld giving strange errors with undefined virtual functions
- To: Smilodon <smilodon at niksula dot hut dot fi>
- Subject: Re: collect2 / ld giving strange errors with undefined virtual functions
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 25 Mar 1999 22:16:10 -0300
- Cc: egcs-bugs at egcs dot cygnus dot com
- References: <Pine.LNX.3.95.990326023645.5280A-100000@jt7-234.tky.hut.fi>
On Mar 25, 1999, Smilodon <smilodon@niksula.hut.fi> wrote:
> Whether this is a bug and if it is in collect2, ld, or egcs, I am not
> sure. When a constructor is declared inline and a virtual method and/or a
> destructor is declared but not defined anywhere, the linker complains
> about an undefined reference to the constructor in the code trying to
> construct an instance of the class.
This is correct behavior. out-of-line versions of constructors are
only emitted in the translation unit in which the first non-inline
non-pure-virtual method of a class is defined. This behavior may seem
awkward, but according to the standard you *must* define all such
methods.
> While this error is a result of an obvious defect in the code being
> compiled, it is still rather confusing to get a message about a missing
> constructor when it is something else that is missing. :)
Yup. But this error is impossible to detect within the compiler, and
when we get to the linker, it's too late :-(
--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Brasil
{oliva,Alexandre.Oliva}@dcc.unicamp.br aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,egcs.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists