From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-05-11 16:14:14
Apparently, g++ 4.0.0 with -O3 manages to optimize out one of the shared_ptr
instances in the example below:
boost::shared_ptr<int> pi(new int);
boost::shared_ptr<int> pi2 = boost::static_pointer_cast<int>(pv);
BOOST_TEST(pi.get() == pi2.get());
BOOST_TEST(!(pi < pi2 || pi2 < pi));
BOOST_TEST(pi.use_count() == 3);
BOOST_TEST(pv.use_count() == 3);
BOOST_TEST(pi2.use_count() == 3);
and the use_count() tests fail.
-O0, 1, 2 are fine, and replacing BOOST_TEST with assert is fine, too.
Printing the use_count() also gives 3, as expected. Must be an interesting
optimizer bug (or feature.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk