| 1 | /*
|
|---|
| 2 | Download Boost from boost.org and extract into "boost_1_55_0".
|
|---|
| 3 | Open VS2010 command prompt and build using the following command. It will build sucessfully.
|
|---|
| 4 | cl BugC2996.cpp /c /EHsc /MD /I"boost_1_55_0"
|
|---|
| 5 |
|
|---|
| 6 | Open VS2012 command prompt and build using the same command. It will fail with error C2996 on the line that calls UnrelatedTemplateFunc.
|
|---|
| 7 | If you add EITHER of the following definitions to the command line, it will build successfully on VS2012:
|
|---|
| 8 | /D "DONT_CALL_FUNC"
|
|---|
| 9 | /D "SER_CLASS=B"
|
|---|
| 10 |
|
|---|
| 11 | So it has something to do with the depth of the serialization, plus calling an unrelated templated function.
|
|---|
| 12 |
|
|---|
| 13 | Please only compile, don't try to link - it will naturally fail.
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | #pragma warning(disable:4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data (problem in Boost, unrelated to the bug in question)
|
|---|
| 17 |
|
|---|
| 18 | #include <fstream>
|
|---|
| 19 | #include <boost/archive/binary_iarchive.hpp>
|
|---|
| 20 | #include <boost/serialization/vector.hpp>
|
|---|
| 21 | #include <boost/serialization/nvp.hpp>
|
|---|
| 22 | #include <boost/serialization/map.hpp>
|
|---|
| 23 | #include <boost/serialization/version.hpp>
|
|---|
| 24 | #include <boost/serialization/export.hpp>
|
|---|
| 25 | #include <boost/serialization/access.hpp>
|
|---|
| 26 | #include <boost/serialization/base_object.hpp>
|
|---|
| 27 | #include <boost/serialization/list.hpp>
|
|---|
| 28 | #include <boost/serialization/shared_ptr.hpp>
|
|---|
| 29 | #include <boost/serialization/shared_ptr_132.hpp>
|
|---|
| 30 | #include <boost/serialization/split_member.hpp>
|
|---|
| 31 | #include <boost/serialization/utility.hpp>
|
|---|
| 32 |
|
|---|
| 33 | struct E
|
|---|
| 34 | {
|
|---|
| 35 | int x;
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 | struct D
|
|---|
| 39 | {
|
|---|
| 40 | std::vector<E> children;
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | struct C
|
|---|
| 44 | {
|
|---|
| 45 | std::vector<D> children;
|
|---|
| 46 | };
|
|---|
| 47 |
|
|---|
| 48 | struct B
|
|---|
| 49 | {
|
|---|
| 50 | std::vector<C> children;
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | struct A
|
|---|
| 54 | {
|
|---|
| 55 | std::vector<B> children;
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | template<class Archive>
|
|---|
| 60 | void serialize(Archive & ar, A& obj, const unsigned int /*file_version*/)
|
|---|
| 61 | {
|
|---|
| 62 | ar & BOOST_SERIALIZATION_NVP(obj.children);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | template<class Archive>
|
|---|
| 66 | void serialize(Archive & ar, B& obj, const unsigned int /*file_version*/)
|
|---|
| 67 | {
|
|---|
| 68 | ar & BOOST_SERIALIZATION_NVP(obj.children);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | template<class Archive>
|
|---|
| 72 | void serialize(Archive & ar, C& obj, const unsigned int /*file_version*/)
|
|---|
| 73 | {
|
|---|
| 74 | ar & BOOST_SERIALIZATION_NVP(obj.children);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | template<class Archive>
|
|---|
| 78 | void serialize(Archive & ar, D& obj, const unsigned int /*file_version*/)
|
|---|
| 79 | {
|
|---|
| 80 | ar & BOOST_SERIALIZATION_NVP(obj.children);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | template<class Archive>
|
|---|
| 84 | void serialize(Archive & ar, E& obj, const unsigned int /*file_version*/)
|
|---|
| 85 | {
|
|---|
| 86 | ar & BOOST_SERIALIZATION_NVP(obj.x);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | template<class T>
|
|---|
| 92 | boost::shared_ptr<T> UnrelatedTemplateFunc(const std::string & argument);
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | #ifndef SER_CLASS
|
|---|
| 96 | #define SER_CLASS A
|
|---|
| 97 | #endif
|
|---|
| 98 |
|
|---|
| 99 | // serialize A and the build will fail (if UnrelatedTemplateFunc is called below)
|
|---|
| 100 | // serialize B instead of A and the build will succeed!
|
|---|
| 101 | void Func(boost::shared_ptr<SER_CLASS> obj)
|
|---|
| 102 | {
|
|---|
| 103 | std::ifstream ifs;
|
|---|
| 104 | boost::archive::binary_iarchive ia(ifs);
|
|---|
| 105 | ia >> obj;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | void OtherFunc()
|
|---|
| 109 | {
|
|---|
| 110 | // comment this line and the build will succeed, whatever struct you decide to serialize above
|
|---|
| 111 | #ifndef DONT_CALL_FUNC
|
|---|
| 112 | UnrelatedTemplateFunc<unsigned char>("");
|
|---|
| 113 | #endif
|
|---|
| 114 | }
|
|---|