Bug in handling virtual functions in egcs 1.0.3 and GCC 2.8.1

Jonathan Mohr mohrj@Berio.Augustana.AB.CA
Thu Jul 30 13:51:00 GMT 1998


I have written an application using derived classes which overload 
operator= as a virtual function.  I have found that GCC 2.7.2.3 correctly
calls operator= in the derived class, but GCC 2.8.1 and egcs 1.0.3 call
operator= in the base class.

I have made a test program available at

	ftp://berio.augustana.ab.ca/pub/testcase.tar.gz

In the test program, I define a Vector class for implementing one-
dimensional arrays with bounds checking and a Matrix class for two-
dimensional arrays with bounds checking.  I also define a Row class which
is derived from Vector, but differs from Vector in that it "knows" that it
is part of a Matrix (e.g., it checks that a row or vector being copied to
a row of the Matrix is of the same size as the other rows of the Matrix.)

A Vector may be copied to a row of a Matrix (provided it is of the same
size as the other rows of the Matrix) by a statement such as:

	M[3] = V;

Similarly, a row of one Matrix can be copied to a row of another Matrix:

	M[3] = A[4];

This is where the problem arises.  The expression M[3] invokes the
overloaded operator[] in the Matrix class, which returns a reference
to a Row.  The assignment operation should then invoke the overloaded
operator= in the Row class and copy the specified Vector (as in the first
example line above) or Row (in the second assignment statement) to the
specified row of matrix M.

Under GCC 2.7.2.3, this works as expected.  Under GCC 2.8.1 and egcs
1.0.3, it invokes operator= in the Vector class (the base class) instead,
even though it has been declared virtual.

Is this a bug, or has the definition of standard C++ be revised to
disallow virtually overloading operators?

Regards,
Jonathan Mohr

---
Jonathan Mohr, Associate Professor of Computing Science
Augustana University College, 4901-46 Ave., Camrose, AB, Canada  T4V 2R3
E-mail: mohrj@augustana.ab.ca  Phone: (403) 679-1514  Fax: (403) 679-1129




More information about the Gcc-bugs mailing list