shared_ptr_test fails on rsi-sol g++ 4

Any ideas why the three use_count() tests: { boost::shared_ptr<int> pi(new int); boost::shared_ptr<void> pv(pi); 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); } fail as described here: http://www.meta-comm.com/engineering/boost-regression/cvs-head/developer/out... http://tinyurl.com/cq7qy ? -- Peter Dimov http://www.pdimov.com

Apparently, g++ 4.0.0 with -O3 manages to optimize out one of the shared_ptr instances in the example below: #include <boost/shared_ptr.hpp> #include <boost/detail/lightweight_test.hpp> int main() { boost::shared_ptr<int> pi(new int); boost::shared_ptr<void> pv(pi); 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); return boost::report_errors(); } 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.)

Peter Dimov wrote:
Apparently, g++ 4.0.0 with -O3 manages to optimize out one of the shared_ptr instances in the example below: ...
Reported as http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21528
participants (1)
-
Peter Dimov