[serialization] Warnings with MSVC 7.1

I've been working on a cut-over of a code-base from Boost 1.34.1 to 1.37 and have found I now get a lot of compiler warnings in the serialization code. The warnings (emitted via BOOST_STATIC_WARNING) appear to be where non-polymorphic objects are serialized via shared_ptr. The boost serialization code seems to want them to be polymorphic. Are these benign warnings that can be disabled? Apologies if this has been raised earlier; I had a good look.. The following example code triggers the warnings (MSVC 7.1): ====== #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/serialization.hpp> #include <boost/serialization/shared_ptr.hpp> using namespace boost; struct X { template <typename T> void serialize(T &ar, const unsigned int version) {} }; typedef boost::shared_ptr<X> X_P; void test_ser() { X_P x_p; std::ifstream ifstr("test.txt"); boost::archive::text_iarchive ar(ifstr); ar & x_p; }

This case is descibed in the rationale section of the documentation. Disregard/disable at your own risk. I don't recommend it. I recommend changing your code to avoid situation which avoids warnings. Robert Ramey Chard wrote:
I've been working on a cut-over of a code-base from Boost 1.34.1 to 1.37 and have found I now get a lot of compiler warnings in the serialization code.
The warnings (emitted via BOOST_STATIC_WARNING) appear to be where non-polymorphic objects are serialized via shared_ptr. The boost serialization code seems to want them to be polymorphic.
Are these benign warnings that can be disabled?
Apologies if this has been raised earlier; I had a good look..
The following example code triggers the warnings (MSVC 7.1):
======
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/serialization.hpp> #include <boost/serialization/shared_ptr.hpp>
using namespace boost;
struct X { template <typename T> void serialize(T &ar, const unsigned int version) {} }; typedef boost::shared_ptr<X> X_P;
void test_ser() { X_P x_p;
std::ifstream ifstr("test.txt"); boost::archive::text_iarchive ar(ifstr); ar & x_p; }
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

"Robert Ramey" <ramey@rrsd.com> wrote in message news:gfj7f6$pmo$1@ger.gmane.org...
This case is descibed in the rationale section of the documentation.
I've had a good read of that, but I don't see the association. The rationale discusses object tracking; the code, as I see it, is not conflicting with that. This is simply compiling the reading code of a *non-polymorphic* type by shared_ptr. For example, if I change X to have a virtual destructor, then the warnings go away, i.e.: struct X { template <typename T> void serialize(T &ar, const unsigned int version) {} virtual ~X() {} };
Disregard/disable at your own risk. I don't recommend it. I recommend
Agreed.
changing your code to avoid situation which avoids warnings.
But in this case the code appears to be correct; the warnings, emitted from boost::serialization, should not be triggered. *The code has also been compiled on gcc 4.3.2 (with -Wall and -W) and does not generate any equivalent warnings.* On MSVC7.1: [...]\boost_1_37_0\boost\serialization\extended_type_info_typeid.hpp(88) : warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class' and on..

I've looked into the code and concluded that you're correct and the warning shouldn't appear. Please open a track item for this bug and I'll fix it. Robert Ramey Chard wrote:
"Robert Ramey" <ramey@rrsd.com> wrote in message news:gfj7f6$pmo$1@ger.gmane.org...
This case is descibed in the rationale section of the documentation.
I've had a good read of that, but I don't see the association. The rationale discusses object tracking; the code, as I see it, is not conflicting with that.
This is simply compiling the reading code of a *non-polymorphic* type by shared_ptr.
For example, if I change X to have a virtual destructor, then the warnings go away, i.e.:
struct X { template <typename T> void serialize(T &ar, const unsigned int version) {}
virtual ~X() {} };
Disregard/disable at your own risk. I don't recommend it. I recommend
Agreed.
changing your code to avoid situation which avoids warnings.
But in this case the code appears to be correct; the warnings, emitted from boost::serialization, should not be triggered.
*The code has also been compiled on gcc 4.3.2 (with -Wall and -W) and does not generate any equivalent warnings.*
On MSVC7.1:
[...]\boost_1_37_0\boost\serialization\extended_type_info_typeid.hpp(88) : warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class'
and on..
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Chard
-
Robert Ramey