/* Download Boost from boost.org and extract into "boost_1_55_0". Open VS2010 command prompt and build using the following command. It will build sucessfully. cl BugC2996.cpp /c /EHsc /MD /I"boost_1_55_0" Open VS2012 command prompt and build using the same command. It will fail with error C2996 on the line that calls UnrelatedTemplateFunc. If you add EITHER of the following definitions to the command line, it will build successfully on VS2012: /D "DONT_CALL_FUNC" /D "SER_CLASS=B" So it has something to do with the depth of the serialization, plus calling an unrelated templated function. Please only compile, don't try to link - it will naturally fail. */ #pragma warning(disable:4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data (problem in Boost, unrelated to the bug in question) #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct E { int x; }; struct D { std::vector children; }; struct C { std::vector children; }; struct B { std::vector children; }; struct A { std::vector children; }; template void serialize(Archive & ar, A& obj, const unsigned int /*file_version*/) { ar & BOOST_SERIALIZATION_NVP(obj.children); } template void serialize(Archive & ar, B& obj, const unsigned int /*file_version*/) { ar & BOOST_SERIALIZATION_NVP(obj.children); } template void serialize(Archive & ar, C& obj, const unsigned int /*file_version*/) { ar & BOOST_SERIALIZATION_NVP(obj.children); } template void serialize(Archive & ar, D& obj, const unsigned int /*file_version*/) { ar & BOOST_SERIALIZATION_NVP(obj.children); } template void serialize(Archive & ar, E& obj, const unsigned int /*file_version*/) { ar & BOOST_SERIALIZATION_NVP(obj.x); } template boost::shared_ptr UnrelatedTemplateFunc(const std::string & argument); #ifndef SER_CLASS #define SER_CLASS A #endif // serialize A and the build will fail (if UnrelatedTemplateFunc is called below) // serialize B instead of A and the build will succeed! void Func(boost::shared_ptr obj) { std::ifstream ifs; boost::archive::binary_iarchive ia(ifs); ia >> obj; } void OtherFunc() { // comment this line and the build will succeed, whatever struct you decide to serialize above #ifndef DONT_CALL_FUNC UnrelatedTemplateFunc(""); #endif }