This is the mail archive of the gcc@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: bug in egcs with C++?


teunis <teunis@computersupportcentre.com> reported a case where he
gets an undefined virtual function table pointer.

As Alexandre and the g++ FAQ (yes, I know it's out of date) point out,
this is caused because there is a missing definition for the first
non-inline virtual function.

However, perhaps we could give a better diagnostic for this case;
Sun's compiler does.  Both g++ and Sun's compiler use the same trick
of emitting the virtual function table definition only in the .o file
that defines the first non-inline virtual function.

Given the test program

------------------------------
class foo {
public:
   virtual void method(); // first non-abstract non-inline method
   virtual void another_method(); // second non-abstract non-inline method
};

void foo::another_method() {}

main () {
    foo bar;
    bar.another_method();
}
------------------------------
doing
CC test.cxx
gives

Undefined                       first referenced
 symbol                             in file
foo::__vtbl                     ttt.o
[Hint: try checking whether the first non-inlined, non-pure virtual function of class foo is defined]

This hint message has to be produced at link time.
Perhaps the GNU linker and/or collect could be modified to add such
a message if an undefined virtual function table is detected.


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