Boost logo

Boost Users :

Subject: [Boost-users] Bug in serialization::make_nvp?
From: stair314 (ia3n_at_[hidden])
Date: 2009-09-04 22:51:16


I'm sorry if this appears twice; I received an e-mail saying it couldn't be
sent because I hadn't subscribed to the mailing list.

When I run the following code, I get this error:
terminate called after throwing an instance of
'boost::archive::xml_archive_exception'
  what(): uninitialized exception
Abort

However, if I substitute BOOST_SERIALIZATION_NVP for the make_nvp function,
it works fine. Am I doing something wrong, or is this a bug?

#include <iostream>
#include <fstream>
#include <string>
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
    using ::remove;
}
#endif

#include <boost/archive/tmpdir.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/nvp.hpp>

class A
{
public:
  A() {}
  virtual ~A() {}
 
  int a;

private:
    friend class boost::serialization::access;
 
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
      {
       
        //ar & BOOST_SERIALIZATION_NVP(a);
        ar & boost::serialization::make_nvp("example field",a);
      };
};

void
restore( const char * filename)
{
  A s;
  // open the archive
  std::ifstream ifs(filename);
  assert(ifs.good());
  boost::archive::xml_iarchive ia(ifs);
 
  // restore the schedule from the archive
    ia >> BOOST_SERIALIZATION_NVP(s);
}

int main(int argc, char *argv[])
{
     std::string filename("/tmp/wtf.xml");

     {
       A s;
       // make an archive
       std::ofstream ofs(filename.c_str());
       assert(ofs.good());
       boost::archive::xml_oarchive oa(ofs);
       oa << BOOST_SERIALIZATION_NVP(s);
     }

    printf("---\n");

    restore( filename.c_str());

    return 0;
}

-- 
View this message in context: http://www.nabble.com/Bug-in-serialization%3A%3Amake_nvp--tp25304627p25304627.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net