#include "stdafx.h" struct X { int x; template void serialize(Archive & ar, const unsigned int /*file_version*/) { ar & x; } }; BOOST_CLASS_IMPLEMENTATION(X, boost::serialization::object_serializable) template void BoostLoad(const char* fileName, T& obj) { std::ifstream ifs(fileName, std::ios_base::binary); boost::archive::binary_iarchive ia(ifs); ia >> obj; } template void BoostSave(const char* fileName, T& obj) { std::ofstream ofs(fileName, std::ios_base::binary); boost::archive::binary_oarchive oa(ofs); oa << obj; } int main() { // instructions: // 1) uncomment this and run to create the file // 2) comment this and run to see that x2 is loaded correctly // 3) enable the below code by changing to #if 1 and run to see that x2 is loaded incorrectly. //X x1 = { 0x31415926 }; //BoostSave("SerializationBug.dat", x1); X x2; BoostLoad("SerializationBug.dat", x2); #if 0 volatile int x = 0; if(x) { X *x3; BoostLoad("this code is never executed", x3); } #endif }