Opened 7 years ago
Closed 7 years ago
#11423 closed Bugs (fixed)
Serialization with versioning not working with (pure virtual) base classes
Reported by: | anonymous | Owned by: | Robert Ramey |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost 1.58.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The versioning feature of the serialization component works fine when using with non-polymorphic classes or derived classes. However, for (pure virtual) base classes the version number set with BOOST_CLASS_VERSION(MyBaseClass, 1) seems to be ignored and during serialization the default version (=0) is always used.
Change History (3)
follow-up: 2 comment:1 by , 7 years ago
comment:2 by , 7 years ago
Replying to ramey:
I can't imagine why this would be a problem.
In order to help with this, I'd really have to see a small example demonstrating the problem.
I stepped through the code and found that what I'm observing (version number ignored) is due to a different reason, though serializing an inheritance hierarchy may be heavily affected by this issue.
Here is what I found: Consider the following class structure that are contained in two different modules (compilation units).
=========== ModuleA.dll ===========
class ClassA {
template<class Archive> void serialize(Archive &ar, const unsigned int uiVersion);
};
BOOST_CLASS_VERSION(ClassA, 1)
===========
ModuleA.dll
===========
===========
ModuleB.dll
===========
class ClassB : public ClassA {
template<class Archive> void serialize(Archive &ar, const unsigned int uiVersion) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ClassA);
}
}
BOOST_CLASS_VERSION(ClassB, 1)
=========== ModuleB.dll ===========
Now consider the following call stack:
[...]
ModuleB.dll!ClassB::serialize(...) <- this triggers BOOST_SERIALIZATION_BASE_OBJECT_NVP(ClassA);
[...]
ModuleB.dll!oserializer<Archive, ClassA>::save_object_data(...) <- this call uses ::boost::serialization::version<ClassA>::value
The problem now is that ::boost::serialization::version<ClassA>::value evaluates to 0 as the specialization (version #1) is only known inside ModuleA.
I think this should be a new ticket if this is indeed the issue...
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
is the resolved? As I haven't heard anything lately, I'm going to close this ticket
I can't imagine why this would be a problem.
In order to help with this, I'd really have to see a small example demonstrating the problem.