gast128:
The case seems entered by Peter Dimov as bug entry:
https://svn.boost.org/trac/boost/ticket/2813
Yes, I consider this a bug. This is the test I've come up with:
#include
#include
class X
{
public:
static int instances;
X()
{
++instances;
}
~X()
{
--instances;
}
private:
X( X const& );
};
int X::instances = 0;
class Y
{
public:
static int instances;
Y()
{
++instances;
}
~Y()
{
--instances;
}
private:
Y( Y const& );
};
int Y::instances = 0;
static boost::shared_ptr<void> s_pv;
class Z
{
public:
static int instances;
Z()
{
++instances;
}
~Z()
{
--instances;
boost::shared_ptr<void> pv( new Y );
s_pv = pv;
}
private:
Z( Z const& );
};
int Z::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
BOOST_TEST( Y::instances == 0 );
BOOST_TEST( Z::instances == 0 );
{
boost::shared_ptr<void> pv( new Z );
s_pv = pv;
}
BOOST_TEST( X::instances == 0 );
BOOST_TEST( Y::instances == 0 );
BOOST_TEST( Z::instances == 1 );
{
boost::shared_ptr<void> pv( new X );
s_pv = pv;
}
BOOST_TEST( X::instances == 0 );
BOOST_TEST( Y::instances == 1 );
BOOST_TEST( Z::instances == 0 );
s_pv.reset();
BOOST_TEST( X::instances == 0 );
BOOST_TEST( Y::instances == 0 );
BOOST_TEST( Z::instances == 0 );
return boost::report_errors();
}