Opened 11 years ago

Last modified 10 years ago

#6515 assigned Bugs

Serilaization of std::vector<bool> is broken for optimizing archives

Reported by: Hartmut Kaiser Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

Serializing a vector<bool> causes corruptions in the created archive. The reason is this function (in boost/serialization/vector.hpp):

template<class Archive, class U, class Allocator>
inline void save(
    Archive & ar,
    const std::vector<U, Allocator> &t,
    const unsigned int /* file_version */,
    mpl::true_
){
    const collection_size_type count(t.size());
    ar << BOOST_SERIALIZATION_NVP(count);
    if (!t.empty())
        ar << make_array(detail::get_data(t),t.size());
}

While detail::get_data(t) is not specialized for std::vector<bool> (but it should be), and t.size() returns the number of bits stored in the vector, which is probably not what's expected either.

I'm encountering this problem with MSVC10, 64bit, Windows7.

Change History (1)

comment:1 by Robert Ramey, 10 years ago

Status: newassigned

Hmmm - looks like a specialization of the serialization for vector<bool> is required. Care to submit one? While you're at it, how about all the type set<bool>? etc.

I recognize that this a problem, but it is non-trivial and seems such a low priority that it would be hard for me to justify the effort to track down all the repercussions of fixing this, testing, etc. etc. However, if you want to do this I would support the effort and you would be rewarded with a thin slice of immortality by having your name included in the acknowledgements in the documentation and code comments/copyright.

So I'm going to remove this from pending issues and put up for the things to do "some day".

Robert Ramey

Note: See TracTickets for help on using tickets.