Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
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.95Aug4125904@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            |
+----------------------------+------------------------------------+



             reply	other threads:[~1995-08-04  4:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-08-04  4:00 Jean-Louis Moser [this message]
1995-08-07  4:00 ` DEC cxx bug (default copy operator and virtual inheritance) Alec Habig
1995-08-14  4:00   ` Bill Kemp
1995-08-14  4:00     ` Andrew Gallatin
1995-08-15  4:00     ` Leo Bicknell
1995-08-15  4:00     ` Dan Pop
1995-08-15  4:00       ` Bill Kemp
1995-08-19  4:00     ` A.Schindler
1995-08-18  4:00   ` Alex Kowalenko
1995-08-20  4:00   ` Daniel S. Riley
  -- strict thread matches above, loose matches on Subject: below --
1995-08-04  4:00 Jean-Louis Moser
1995-08-16  4:00 ` Dennis Murphy
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