This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: collect2 / ld giving strange errors with undefined virtual functions


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]