Opened 9 years ago

Closed 9 years ago

#8726 closed Bugs (fixed)

GCC 4.8 warns of variable set but not used

Reported by: Chris Stylianou <chris5287@…> Owned by: Robert Ramey
Milestone: Boost 1.54.0 Component: serialization
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

When compiling with -Wall (GCC 4.8.0) the following warning is raised as an error:

libs/serialization/src/basic_iarchive.cpp: In member function ‘const boost::archive::detail::basic_pointer_iserializer* boost::archive::detail::basic_iarchive_impl::load_pointer(boost::archive::detail::basic_iarchive&, void*&, const boost::archive::detail::basic_pointer_iserializer*, const boost::archive::detail::basic_pointer_iserializer* (*)(const boost::serialization::extended_type_info&))’:
libs/serialization/src/basic_iarchive.cpp:455:23: error: variable ‘new_cid’ set but not used [-Werror=unused-but-set-variable]
         class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer());

new_cid is only used to perform a BOOST_ASSERT, maybe this could be collapsed into one line?

Index: libs/serialization/src/basic_iarchive.cpp
===================================================================
--- libs/serialization/src/basic_iarchive.cpp   (revision 84899)
+++ libs/serialization/src/basic_iarchive.cpp   (working copy)
@@ -452,10 +452,9 @@
             bpis_ptr = (*finder)(*eti);
         }
         BOOST_ASSERT(NULL != bpis_ptr);
-        class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer());
+        BOOST_ASSERT(register_type(bpis_ptr->get_basic_serializer()) == cid);
         int i = cid;
         cobject_id_vector[i].bpis_ptr = bpis_ptr;
-        BOOST_ASSERT(new_cid == cid);
     }
     int i = cid;
     cobject_id & co = cobject_id_vector[i];

Attachments (1)

8726_simpler_patch.patch (542 bytes ) - added by Jeremiah Willcock 9 years ago.
Minimal patch to fix warning

Download all attachments as: .zip

Change History (8)

comment:1 by Robert Ramey, 9 years ago

Resolution: invalid
Status: newclosed

Hmmm - this wouldn't work.

It would mean that when compiling for release mode, the register_type function wouldn't get called.

Note that this will only emit the warning in debug mode.

I'm going to mark this idea as not valid - feel free to re-open if if you get a better idea.

RObert Ramey

comment:2 by Chris Stylianou <chris5287@…>, 9 years ago

Resolution: invalid
Status: closedreopened

True, but it would still be nice to silence the unused warning. Could you use BOOST_VERIFY instead of BOOST_ASSERT?

comment:3 by Robert Ramey, 9 years ago

Resolution: fixed
Status: reopenedclosed

Ok _ i patched this. Subject to test

comment:4 by Chris Stylianou <chris5287@…>, 9 years ago

Great, could you post a link to the changeset when it has been done.

comment:5 by Chris Stylianou <chris5287@…>, 9 years ago

Resolution: fixed
Status: closedreopened

Still awaiting changeset, could this be closed only once the changeset has been committed and linked here.

by Jeremiah Willcock, 9 years ago

Attachment: 8726_simpler_patch.patch added

Minimal patch to fix warning

comment:6 by Jeremiah Willcock, 9 years ago

I have attached a simpler patch; this version is unlikely to break anything else since it only adds a cast to void to avoid the warning.

comment:7 by Robert Ramey, 9 years ago

Resolution: fixed
Status: reopenedclosed

fixed in next release

Note: See TracTickets for help on using tickets.