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++/11913] New: Strange "undefined reference" for inline'ly defined member function of a derived class


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Strange "undefined reference" for inline'ly defined
                    member function of a derived class
           Product: gcc
           Version: 2.95.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: melkov at arc dot yandex dot ru
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-freebsd-gnu
  GCC host triplet: i686-freebsd-gnu
GCC target triplet: i686-freebsd-gnu

System: FreeBSD 4.7, 4.8; intel 686
Gcc: 2.95.2, 2.95.4
ld: 2.11.2, 2.12.1
command line: c++ -O0 *.cpp
files: foo.cpp bar.cpp foo.h

Problem:
inline function B::C() is declared in foo.h, but defined and used only in foo.h.
Linker says:
/var/tmp/ccP9I2i8.o: In function `B::D(void) const':
/var/tmp/ccP9I2i8.o(.text+0xf): undefined reference to `B::C(void) const'

a) Compiling with -O1 | -O2 | -O3 hides the problem.
b) Defining B::C() as non-inline function hides the problem
c) Putting B::C() definition into a header file, as well all putting all the 
code into a single file also hides the problem.
d) egcs-3.1.1 compiles and links that fine

Actually (a) is impossible for debug builds, (b) and (c) will break the design 
and text formatting of the program that is affected by the bug. And we are 
still not ready for (d).

==> foo.h <==
#ifndef __foo_h__
#define __foo_h__

class A {
public:
    virtual ~A() {}
};

class B : public A {
public:
    ~B();
    int D() const;
    int C() const;
};

#endif //__foo_h__

==> foo.cpp <==
#include "foo.h"

inline
int B::C() const {
    return 1;
}

int B::D() const {
    return C();
}

==> bar.cpp <==
#include "foo.h"

B::~B() {}

B b;

int main() {
    b.D();
    return 0;
}


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