From: jlm@ludo.two-oo-one.fr (Jean-Louis Moser)
Subject: DEC cxx bug (default copy operator and virtual inheritance)
Date: 1995/08/04 [thread overview]
Message-ID: <JLM.95Aug4125839@ludo.two-oo-one.fr> (raw)
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 <iostream.h>
#include <assert.h>
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 |
+----------------------------+------------------------------------+
next reply other threads:[~1995-08-04 4:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-08-04 4:00 Jean-Louis Moser [this message]
-- strict thread matches above, loose matches on Subject: below --
1995-08-04 4:00 DEC cxx bug (default copy operator and virtual inheritance) Jean-Louis Moser
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox