This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug in invoking virtual functions in g++ 2.8.1/egcs 1.0.3 release


Subsequent to sending my previous message containing a simple example
illustrating what I take to be a bug in resolving the virtual overloading
of operator=, I found an even simpler example to illustrate the same bug.

When the following program is compiled on an i586 machine running Linux
with g++ version 2.7.2.3, it (correctly) invokes Derived::operator= and
reports that 'x' contains 2.  However, when compiled on a Cyrix 6x86
machine running Linux with egcs-2.90.29 980515 (egcs-1.0.3 release),
it invokes Base::operator= and reports that 'x' contains 1.

Can anyone else duplicate this result?  Is this actually a compiler bug,
or was there some change in standard C++ that makes this program illegal?

----------------------- snip ------------------------------------
//
//  An even simpler test of virtual overloading of operator= in  C++.
//
//  Under g++ 2.7.2.3, this program properly shows that 'x' contains 2.
//  Under egcs-2.90.29 980515 (egcs-1.0.3 release) [and g++ 2.8.1],
//  the program shows 'x' as containing 1 (i.e., it executes virtual
//  function Base::op= instead of Derived::op=).
//
//  J. Mohr  1998 August 5
//

#include <iostream.h>


class Base
{
public:
  Base() { value = 0; }
  virtual void operator= ( Base& b ) { value = 1; }
  int value;
};


class Derived : public Base
{
public:
  virtual void operator= ( Base& b ) { value = 2; }
};


void main()
{
  Derived x, d;

  x = d;
  cout << "x contains " << x.value << " (should be 2).\n";
}
----------------------- snip ------------------------------------

Sorry for the nuisance of sending the previous not-as-simple example.

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





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]