[Serialization] can BOOST_ASSERT have method calls?

I noticed in serializations basic_iarchive that when you're not building for debug the next line here (317 in basic_iarchive.cpp) has a warning for unused variable new_cid. The BOOST_ASSERT is instantiated as ((void)0) so new_cid really isn't used. Could the register_type call be moved into the assert? class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer()); int i = cid; cobject_id_vector[i].bpis_ptr = bpis_ptr; BOOST_ASSERT(new_cid == cid); Something like: BOOST_ASSERT(register_type(bpis_ptr->get_basic_serializer()) == cid); Then the new_cid variable wouldn't be needed and the call to register_type would disappear with the BOOST_ASSERT if you aren't building for debug. Or, does the call to register_type have an important side effect that is required? Patrick

Patrick Horgan wrote:
I noticed in serializations basic_iarchive that when you're not building for debug the next line here (317 in basic_iarchive.cpp) has a warning for unused variable new_cid. The BOOST_ASSERT is instantiated as ((void)0) so new_cid really isn't used. Could the register_type call be moved into the assert?
class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer()); int i = cid; cobject_id_vector[i].bpis_ptr = bpis_ptr; BOOST_ASSERT(new_cid == cid);
Something like:
BOOST_ASSERT(register_type(bpis_ptr->get_basic_serializer()) == cid);
IIRC, register_type would not be called in release builds. MSFT had a VERIFY macro which asserted in debug, and still executed the statement in release builds. Or am I mistaken about BOOST_ASSERT's implementation? Jeff

Jeff Flinn wrote:
Patrick Horgan wrote:
I noticed in serializations basic_iarchive that when you're not building for debug the next line here (317 in basic_iarchive.cpp) has a warning for unused variable new_cid. The BOOST_ASSERT is instantiated as ((void)0) so new_cid really isn't used. Could the register_type call be moved into the assert?
class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer()); int i = cid; cobject_id_vector[i].bpis_ptr = bpis_ptr; BOOST_ASSERT(new_cid == cid);
Something like:
BOOST_ASSERT(register_type(bpis_ptr->get_basic_serializer()) == cid);
IIRC, register_type would not be called in release builds. MSFT had a VERIFY macro which asserted in debug, and still executed the statement in release builds. Or am I mistaken about BOOST_ASSERT's implementation?
Looks like there already is BOOST_VERIFY. So BOOST_VERIFY(register_type(bpis_ptr->get_basic_serializer()) == cid); Would do the right thing in both release and debug builds, as well as honor BOOST_DISABLE_ASSERTS. Jeff

Patrick Horgan wrote:
I noticed in serializations basic_iarchive that when you're not building for debug the next line here (317 in basic_iarchive.cpp) has a warning for unused variable new_cid. The BOOST_ASSERT is instantiated as ((void)0) so new_cid really isn't used. Could the register_type call be moved into the assert?
class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer()); int i = cid; cobject_id_vector[i].bpis_ptr = bpis_ptr; BOOST_ASSERT(new_cid == cid);
Something like:
BOOST_ASSERT(register_type(bpis_ptr->get_basic_serializer()) == cid);
Then the new_cid variable wouldn't be needed and the call to register_type would disappear with the BOOST_ASSERT if you aren't building for debug.
which would break the program.
Or, does the call to register_type have an important side effect that is required?
It does. It must be called. What is optional is checking the return type. I do this during debug to verify code. I suppose the motiviation here is to eliminate a spurious warning. This could be done but doing a little #ifdef hack. If you want to do this, make a patch, test it and submit it through the track system. Robert Ramey
Patrick _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Jeff Flinn
-
Patrick Horgan
-
Robert Ramey