Compiler adds undefined symbol reference for virtual functions....

T

trond.norbye

Hi

I am trying to compile a quite large software system with a new
compiler. During that attempt I am facing problems during the link
phase, and I have traced it down to the following construct:

test.cc:
class Foo
{
public:
virtual ~Foo();
};

class Bar : public Foo
{
public:
virtual ~Bar() {};
};

If I compile this unit all of the previous compilers I have tried will
generate _no_ symbols, since I don't actually use anything here. The
new compiler I have tried gives me:

Undefined symbols from test.o:
typeid<Foo>
Foo::~Foo()
Class tables [Vtable] dependent on key function:
"__versioned_type_info::~__versioned_type_info()"

So the question is as simple as: Is this a "bug" in the new compiler I
have used, or is it "allowed" to do this according to the
specification...

(In my "real" program the classes reside in separate header files
included by a lot of different "modules" in my system...)

Trond
 
V

Victor Bazarov

I am trying to compile a quite large software system with a new
compiler. During that attempt I am facing problems during the link
phase, and I have traced it down to the following construct:

test.cc:
class Foo
{
public:
virtual ~Foo();

A virtual function will be defined or declared pure or both. You
cannot declare a function virtual without providing its definition
somewhere. Period.
};

class Bar : public Foo
{
public:
virtual ~Bar() {};
};

If I compile this unit all of the previous compilers I have tried will
generate _no_ symbols, since I don't actually use anything here. The
new compiler I have tried gives me:

Undefined symbols from test.o:
typeid<Foo>
Foo::~Foo()
Class tables [Vtable] dependent on key function:
"__versioned_type_info::~__versioned_type_info()"

So the question is as simple as: Is this a "bug" in the new compiler I
have used, or is it "allowed" to do this according to the
specification...

It is not allowed to have a virtual function that is not pure without
a definition. You can only omit the definition of a virtual function
iff you declare it pure.
(In my "real" program the classes reside in separate header files
included by a lot of different "modules" in my system...)

That doesn't matter.

V
 
T

trond.norbye

Victor said:
It is not allowed to have a virtual function that is not pure without
a definition. You can only omit the definition of a virtual function
iff you declare it pure.


That doesn't matter.

This was _exactly_ the kind of information I was looking for :)

regards,

Trond
 
G

Greg Comeau

I am trying to compile a quite large software system with a new
compiler. During that attempt I am facing problems during the link
phase, and I have traced it down to the following construct:

test.cc:
class Foo
{
public:
virtual ~Foo();
};

class Bar : public Foo
{
public:
virtual ~Bar() {};
};

If I compile this unit all of the previous compilers I have tried will
generate _no_ symbols, since I don't actually use anything here. The
new compiler I have tried gives me:

Undefined symbols from test.o:
typeid<Foo>
Foo::~Foo()
Class tables [Vtable] dependent on key function:
"__versioned_type_info::~__versioned_type_info()"

So the question is as simple as: Is this a "bug" in the new compiler I
have used, or is it "allowed" to do this according to the
specification...

(In my "real" program the classes reside in separate header files
included by a lot of different "modules" in my system...)

I don't have my standard in front of me, but I'm fairly
certain that it says that the virtuals need to be defined
but that a diagnostic is not required.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top