Article View: gnu.g++.bug
Article #447virtual functions and MI bug
From: Paul Vaughan
Date: Thu, 28 Sep 1989 17:54
Date: Thu, 28 Sep 1989 17:54
114 lines
3380 bytes
3380 bytes
You've probably already read about this on the net, but just
to make sure you're aware . . . g++ 1.36.0- doesn't implement virtual
functions correctly in a certain case of MI.
Jonathan Shopiro writes [and I expect he's correct about cfront 2.0]:
As a simple example of how the language should behave:
struct A {
virtual void foo();
};
struct B {
virtual void foo();
};
struct C : A, B {
virtual void foo();
};
void
bar()
{
C c;
A* ap = &c;
B* bp = &c;
C* cp = &c;
// these calls all do the same thing
ap->foo(); // calls C::foo()
bp->foo(); // calls C::foo()
cp->foo(); // calls C::foo()
}
------------------------------
But I find that the following program, copied and completed from his code
#include <stream.h>
struct A {
virtual void foo();
};
void A::foo() {
cout << "A::foo()\n" ;
}
struct B {
virtual void foo();
};
void B::foo() {
cout << "B::foo()\n" ;
}
struct C : A, B {
virtual void foo();
};
void C::foo() {
cout << "C::foo()\n" ;
}
void
bar()
{
C c;
A* ap = &c;
B* bp = &c;
C* cp = &c;
// these calls all do the same thing
ap->foo(); // calls C::foo()
bp->foo(); // calls C::foo()
cp->foo(); // calls C::foo()
}
main() {
bar();
}
prints
[1.141]puma) miv
C::foo()
B::foo()
C::foo()
when compiled like this
[1.53]puma) /usr/local/gnu/1.36.0/bin/g++ -v
g++ version 1.36.0-
make miv
/usr/local/gnu/1.36.0/bin/g++ -g -B/usr/local/gnu/1.36.0/lib/gcc- -e __start -g -O -DX11 -I/net/suntrek/d0/newton/systems/include -I/usr/local/gnu/1.36.0/lib/g++-include -o miv miv.cc -L/usr/local/InterViews/lib/SUN3 -lgraphic -ltext -lInterViewsX11 -lX
11 -lm
ld.so: warning: /usr/lib/libc.so.0.10.1 has older revision than expected 12
If I change the C class to inherit virtually from A and B, I get
[1.67]puma) make miv
/usr/local/gnu/1.36.0/bin/g++ -g -B/usr/local/gnu/1.36.0/lib/gcc- -e __start -g -O -DX11 -I/net/suntrek/d0/newton/systems/include -I/usr/local/gnu/1.36.0/lib/g++-include -o miv miv.cc -L/usr/local/InterViews/lib/SUN3 -lgraphic -ltext -lInterViewsX11 -lX
11 -lm
miv.cc:15: ambiguous virtual function `void B::foo ()'
miv.cc:7: ambiguating function `void A::foo ()' (joined by type `C')
This doesn't seem correct to me, since C has it's own C::foo() to
disambiguate it, but I'm not an expert on that.
Has this been fixed? BTW, should I be worried about the warning I'm
getting (maybe the problem is just mine)? Also, I've been getting
occasional Segmentation faults from the compiler (same version) when
working with MI and virtual methods that are supposed to be local
declarations of an inherited method when the local spec doesn't quite
match the spec of the inherited method. I haven't tried to distill
that into a small example though. It's particularly nasty because it
sometimes doesn't even print an error message or line number.
Technical Details
Message-ID:
<8909281754.AA08355@puma.cad.mcc.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!MCC.COM!vaughan%cadillac.cad.mcc.comShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!MCC.COM!vaughan%cadillac.cad.mcc.com From: vaughan%cadillac.cad.mcc.com@MCC.COM (Paul Vaughan) Newsgroups: gnu.g++.bug Subject: virtual functions and MI bug Message-ID: <8909281754.AA08355@puma.cad.mcc.com> Date: 28 Sep 89 17:54:17 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 114