Opened 5 years ago
Last modified 5 years ago
#13456 new Bugs
Object tracking fails with pointer to variant's content
Reported by: | Owned by: | Robert Ramey | |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | variant tracking | Cc: |
Description
Object tracking fails with a pointer to an object contained into a variant that is an element of a container which loads the value_type into a local object. For example a map with a variant as a mapped_type.
There is a pull request: https://github.com/boostorg/serialization/pull/96
Demo:
struct Foo { int i; template<typename Archive> void serialize(Archive& ar, const unsigned int version) { ar & i; } }; int main() { using map_t = std::unordered_map<std::string, boost::variant<Foo, float>>; std::string testfile{"/tmp/serialized"}; { map_t map{{"key", Foo{5}}}; auto ptr = &boost::strict_get<Foo>(map.begin()->second); std::ofstream os(testfile); boost::archive::text_oarchive oa(os); oa << map; oa << ptr; } { std::ifstream is(testfile, (std::ios_base::openmode)0); boost::archive::text_iarchive ia(is, 0); map_t map; Foo* ptr; ia >> map; ia >> ptr; assert(ptr->i == 5); } }
Attachments (1)
Change History (4)
by , 5 years ago
Attachment: | bug_serialization_variant.tgz added |
---|
comment:1 by , 5 years ago
Version: | Boost 1.63.0 → Boost Development Trunk |
---|
comment:2 by , 5 years ago
Sorry, my pull request(#96) does not compile at some platforms. I will fix this.
comment:3 by , 5 years ago
Pull request with a bugfix proposal https://github.com/boostorg/serialization/pull/98
Note:
See TracTickets
for help on using tickets.
Demo