The following portion of shared_ptr_test.cpp: #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(); } (using the current Boost CVS HEAD that will become 1.33 soon) fails the three use_count() tests with g++ 4.0.0 -O3, but not with -O0, 1, 2. It seems that a reference count increment is being optimized away. This does not happen if BOOST_TEST is replaced with assert. -- Summary: Boost shared_ptr_test.cpp fails with -O3 Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: pdimov at gmail dot com CC: gcc-bugs at gcc dot gnu dot org GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21528