After updating to Boost 1.74 I am getting too many warning messages along with a compilation error.
/usr/include/boost/date_time/posix_time/time_serialize.hpp:48:1: error: ‘split_free’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
...
/usr/include/boost/serialization/split_free.hpp:64:13: note: ‘template<class Archive, class T> void boost::serialization::split_free(Archive&, T&, unsigned int)’ declared here, later in the translation unit
origin of this error is
ar & BOOST_SERIALIZATION_NVP(_created);
_created
is of type boost::posix_time::ptime
Is it a bug ? or something new is introduced in 1.74 that caused it ? How to fix it ?
That's minor deficiency in the Boost Datetime library. The serialization header does not include all required headers.
This reproduces for Boost 1.74.0 on GCC 10:
#include <boost/date_time.hpp>
using boost::posix_time::ptime;
#include <boost/date_time/posix_time/time_serialize.hpp>
#include <boost/archive/xml_oarchive.hpp>
int main() {
boost::archive::xml_oarchive oa(std::cout);
ptime _created = boost::posix_time::second_clock::local_time();
oa & BOOST_SERIALIZATION_NVP(_created);
}
Swapping the order of the includes:
#include <boost/archive/xml_oarchive.hpp>
#include <boost/date_time/posix_time/time_serialize.hpp>
Is enough to fix it: Live ON Coliru
Prints
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="17">
<_created class_id="0" tracking_level="0" version="0">
<ptime_date class_id="1" tracking_level="0" version="0">
<date>20201212</date>
</ptime_date>
<ptime_time_duration class_id="2" tracking_level="0" version="1">
<is_special>0</is_special>
<time_duration_hours>23</time_duration_hours>
<time_duration_minutes>26</time_duration_minutes>
<time_duration_seconds>38</time_duration_seconds>
<time_duration_fractional_seconds>0</time_duration_fractional_seconds>
</ptime_time_duration>
</_created>
</boost_serialization>