wrong reference in a virtual table

Igor Levko hornet@reksoft.ru
Fri Jun 19 04:10:00 GMT 1998


Hello,

Herewith I send you my bug report.
I have gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
for Solaris 2.5.1.

It's not so simple to describe the problem verbally,
that's why I attach a simple example with makefile
to illustrate a bug.

There is a trick here. There are two classes defined with the same name
- X
but the definitions are in different .cc files. So that it is to be Ok.
a.cc - X::CONTEXT_A and in b.cc X::CONTEXT_B
Both CONTEXT_A and CONTEXT_B have the virtual function check() which is
redefined in X. But it's defined as check(A&) in X (a.cc) and check(B&)
in X (b.cc).

There are two targets ztest and xtest in makefile. The only difference
between
them is in order of .o files and that's affect the executable.

Please compile the all, try them and see the outputs.
Theoretically there are should be:
X::CONTEXT_B::check(B&) is to be called !!!
-> X::CONTEXT_A::check(B&) 
X::CONTEXT_A::check(A&) is to be called !!!
-> X::CONTEXT_A::check(A&)
doesn't matter which executeable was invoked,
and after compiling by SunC++ 4.2 it is.
But after compiling by egcs I have:
X::CONTEXT_B::check(B&) is to be called !!!
-> X::CONTEXT_B::check(B&)
X::CONTEXT_A::check(A&) is to be called !!!
-> X::CONTEXT_B::check(B&)
                      ^^^
Debuging it with 'set vtbl on' option I could suggest that the problem
is connected
to the virtual table reference.

I wonder if this bug is known already. If so, is there any patch/update
or I have to wait.
Thanks in advance.
Please answer by e-mail:hornet@reksoft.ru

Best regards,
Igor Levko
#include "iostream.h"
#include "a.hh"

int CONTEXT_A::find(A& p)
{
    cout << "X::CONTEXT_A::check(A&) is to be called !!!" << endl;
    
    check(p);

    return 0;
}

class X : public CONTEXT_A
{
public:
    int check(A&) {
	cout << "-> X::CONTEXT_A::check(A&) " << endl;
	return 1;
    }
};

void A::navigate()
{
  X tempContext;
  tempContext.find(*this);
};


More information about the Gcc-bugs mailing list