[gnu.g++.bug] virtual functions and MI bug

vaughan%cadillac.cad.mcc.com@MCC.COM (Paul Vaughan) (09/29/89)

	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.

tiemann@arkesden.eng.sun.com (Michael Tiemann) (10/02/89)

Turned out to be easy to fix this bug.

Michael