From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,2130a6da39d0b2da,start X-Google-Attributes: gidfee84,public X-Google-Thread: f678f,2130a6da39d0b2da,start X-Google-Attributes: gidf678f,public From: jlm@ludo.two-oo-one.fr (Jean-Louis Moser) Subject: DEC cxx bug (default copy operator and virtual inheritance) Date: 1995/08/04 Message-ID: #1/1 X-Deja-AN: 107426399 distribution: world organization: 2001 S.A. followup-to: comp.unix.osf.osf1 newsgroups: comp.unix.osf.osf1,comp.unix.osf.misc Here is a bug in default copy operator and virtual inheritance in DEC C++ V5.0-3 for DEC OSF/1 (Alpha) Is there any correction. We can notice that there is no problem with Gnu g++ in the same case. 1/ try class B virtual from A => after the B part of c (it's bc) has been affected with a B, the address of the A part of C change. it become the same address than the B part as if B won't be virtual from A. => here is the bug. The assertion fail. 2/ try class B NOT virtual from A. DON'T define B::operator = => everything is ok 3/ define B::operator = => everything is ok 4/ Implement C without data member. DON'T define B::operator = => everything is ok --------------------------------------------------------------------- #include #include class A { public: unsigned a_; }; class B : public /**/virtual/**/ A { // (phase 2) public: unsigned b_; B (int b = 0) : b_ (b) {} // B& operator = (const B& b) {b_ = b.b_; return *this;} // (phase 3) }; class C : public B { public: unsigned c_; // (phase 4) C (int c) : c_ (c) {} }; static void dump (C& c) { A& a = c; B& b = c; cout << "C | c_ | B | A | a_ " << &c << " | " << (char*)&c.c_ - (char*)&c << " | " << (char*)&b - (char*)&c << " | " << (char*)&a - (char*)&c << " | " << (char*)&c.a_ - (char*)&c << endl; } void main () { B b = 99; C c = 101; B& cb = c; dump (c); cb = b; // here is the bug dump (c); assert (c.c_ == 101); } -- +----------------------------+------------------------------------+ | Jean-Louis Moser | 2001 SA | | tel: 33 (1)46.60.57.22 | 2, rue de la renaissance | | Email: jlm@two-oo-one.fr | F-92184 Antony Cedex | +----------------------------+------------------------------------+