Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/boost/serialization/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ struct tracking_level<
variant<BOOST_VARIANT_ENUM_PARAMS(T)>
>{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< ::boost::serialization::track_always> type;
typedef mpl::int_< ::boost::serialization::track_selectively> type;
BOOST_STATIC_CONSTANT(int, value = type::value);
};

Expand All @@ -304,7 +304,7 @@ struct tracking_level<
std::variant<Types...>
>{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< ::boost::serialization::track_always> type;
typedef mpl::int_< ::boost::serialization::track_selectively> type;
BOOST_STATIC_CONSTANT(int, value = type::value);
};
#endif
Expand Down
32 changes: 32 additions & 0 deletions test/test_variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,41 @@ void test(Variant & v)
test_type(v);
}

// Serializing the same variant twice by value must store two independent
// values, not an object reference the loader cannot resolve into a separate
// destination object. Regression test for issue #203.
template<class Variant>
void test_reuse(const Variant & v){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(testfile != NULL);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("first", v);
oa << boost::serialization::make_nvp("second", v);
}
Variant v1;
Variant v2;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("first", v1);
ia >> boost::serialization::make_nvp("second", v2);
}
BOOST_CHECK(are_equal(v, v1));
BOOST_CHECK(are_equal(v, v2));
std::remove(testfile);
}

int test_boost_variant(){
std::cerr << "Testing boost_variant\n";
boost::variant<bool, int, float, double, A, std::string> v;
test(v);
const A a;
boost::variant<bool, int, float, double, const A *, std::string> v1 = & a;
test_type(v1);
v = 1;
test_reuse(v);
return EXIT_SUCCESS;
}

Expand All @@ -214,6 +242,8 @@ int test_boost_variant2(){
const A a;
boost::variant2::variant<bool, int, float, double, const A *, std::string> v1 = & a;
test_type(v1);
v = 1;
test_reuse(v);
return EXIT_SUCCESS;
}
#endif
Expand All @@ -228,6 +258,8 @@ int test_std_variant(){
const A a;
std::variant<bool, int, float, double, const A *, std::string> v1 = & a;
test_type(v1);
v = 1;
test_reuse(v);
return EXIT_SUCCESS;
}
#endif
Expand Down