From: David B. Held (dheld_at_[hidden])
Date: 2002-07-30 17:05:24


"Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message
news:ai6vf2$iei$1_at_main.gmane.org...
> [...]
> Y * pY = new Derived;
> delete pY;
>
> Will result in a segmentation fault.
> [...]

Even if Y::~Y is virtual? For instance, consider the following:

#include <iostream>

struct X
{
    int x;
    virtual ~X() { std::cout << "~X()" << std::endl; }
};

struct Y
{
    int y;
    virtual ~Y() { std::cout << "~Y()" << std::endl; }
};

struct D : public X, public Y
{
    virtual ~D() { std::cout << "~D()" << std::endl; }
};

int main()
{
    X* x = new D;
    delete x;
}

Built with gcc 3.0, the output I get from this program is:

~D()
~Y()
~X()

with no segfault. Can squad_ptr<> do that? If you add this line (and
the appropriate #include):

boost::shared_ptr<X> p(new D);

you get a second set of output same as the first. The only way I can
see that you can have a safe embedded count that works
polymorphically (with MI and without numerous hacks) is to use virtual
inheritance of the counter.

Dave