[Boost-bugs] [Boost C++ Libraries] #13456: Object tracking fails with pointer to variant's content

Subject: [Boost-bugs] [Boost C++ Libraries] #13456: Object tracking fails with pointer to variant's content
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-02-24 14:06:05


#13456: Object tracking fails with pointer to variant's content
-------------------------------------------------+-------------------------
 Reporter: Ricardo Calheiros de Miranda Cosme | Owner: Robert
  <ricardo.cosme@…> | Ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component:
                                                 | serialization
  Version: Boost 1.63.0 | Severity: Problem
 Keywords: variant tracking |
-------------------------------------------------+-------------------------
 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);
     }
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac10/ticket/13456>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2018-02-24 14:09:55 UTC