Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* DEC cxx bug (default copy operator and virtual inheritance)
@ 1995-08-04  4:00 Jean-Louis Moser
  1995-08-07  4:00 ` Alec Habig
  0 siblings, 1 reply; 12+ messages in thread
From: Jean-Louis Moser @ 1995-08-04  4:00 UTC (permalink / 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            |
+----------------------------+------------------------------------+



^ permalink raw reply	[flat|nested] 12+ messages in thread
* DEC cxx bug (default copy operator and virtual inheritance)
@ 1995-08-04  4:00 Jean-Louis Moser
  1995-08-16  4:00 ` Dennis Murphy
  0 siblings, 1 reply; 12+ messages in thread
From: Jean-Louis Moser @ 1995-08-04  4:00 UTC (permalink / 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            |
+----------------------------+------------------------------------+



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1995-08-20  4:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-08-04  4:00 DEC cxx bug (default copy operator and virtual inheritance) Jean-Louis Moser
1995-08-07  4:00 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox