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]
Other format: [Raw text]

[Bug c++/17338] New: Linker error message is a triumph of misdirection


	Feed the compiler the following erroneous code:

class Base { public: virtual void Method(void) /* = 0 */; }; // missing text
class Derived : public Base { public: virtual void Method(void) {} };
int main(void)
{
	Derived thing;
	Base *ptr = &thing;
	ptr->Method();
	return 0;
}

	You will get an error message which makes no mention of the actual
	problem (no definition of virtual function in base class, nor does the
	base class overtly = 0 it):

g++ -Wall    virtual.cpp   -o virtual
/usr/local/home/eddy/.sys/tmp/ccAtrV2C.o(.gnu.linkonce.t._ZN4BaseC2Ev+0x8): In function `Base::Base[not-in-charge]()':
: undefined reference to `vtable for Base'
/usr/local/home/eddy/.sys/tmp/ccAtrV2C.o(.gnu.linkonce.r._ZTI7Derived+0x8): undefined reference to `typeinfo for Base'
collect2: ld returned 1 exit status

	Also present in 3.4.1:

g++-3.4 -Wall    virtual.cpp   -o virtual
/usr/local/home/eddy/.sys/tmp/ccNDFkO3.o(.gnu.linkonce.t._ZN4BaseC2Ev+0x8): In function `Base::Base()':
: undefined reference to `vtable for Base'
/usr/local/home/eddy/.sys/tmp/ccNDFkO3.o(.gnu.linkonce.r._ZTI7Derived+0x8): undefined reference to `typeinfo for Base'
collect2: ld returned 1 exit status

The complaint directs me to the constructor; I have seen it attribute
this to a line in a header file from a third-party library.  I have seen
this (on larger and more complex code) without the message about
typeinfo for Base being absent; only the vtable's absence was reported.

Environment:
System: Linux whorl 2.4.26-1-686-smp #1 SMP Sat May 1 19:17:11 EST 2004 i686 GNU/Linux
Architecture: i686
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux

How-To-Repeat:
	When reporting a compiler error, preprocessor output must be included - OK, here it is:
g++ -E virtual.cpp
# 1 "virtual.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "virtual.cpp"
class Base { public: virtual void Method(void) ; };
class Derived : public Base { public: virtual void Method(void) {} };
int main(void)
{
        Derived thing;
        Base *ptr = &thing;
        ptr->Method();
        return 0;
}

-- 
           Summary: Linker error message is a triumph of misdirection
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eddy at opera dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17338


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