Boost C++ Libraries: Ticket #13563: Error deserializing empty forward_list https://svn.boost.org/trac10/ticket/13563 <p> Deserializing an empty forward_list is broken if the elements aren't default constructible (with old compilers it's enough that elements have a non-trivial default constructor). </p> <p> A patch is attached. The problem is that the first element is always loaded first, even if the list is empty. The result may be a crash or any undefined behavior, since deserialization goes out of sync. </p> <p> Test case: </p> <pre class="wiki">#include &lt;boost/serialization/forward_list.hpp&gt; #include &lt;boost/archive/binary_iarchive.hpp&gt; #include &lt;boost/archive/binary_oarchive.hpp&gt; #include &lt;forward_list&gt; #include &lt;iostream&gt; #include &lt;sstream&gt; struct Foo { int x; Foo(int a) : x(a) {}; template&lt;class Archive&gt; void serialize(Archive&amp; ar, const unsigned int) { ar &amp; x; } private: friend class boost::serialization::access; Foo() = default; }; int main() { std::forward_list&lt;Foo&gt; flist; std::ostringstream oss; boost::archive::binary_oarchive oa{oss}; oa &lt;&lt; flist; std::istringstream iss{oss.str()}; boost::archive::binary_iarchive ia{iss}; ia &gt;&gt; flist; } </pre><p> Results in: </p> <pre class="wiki">terminate called after throwing an instance of 'boost::archive::archive_exception' what(): input stream error Aborted (core dumped) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13563 Trac 1.4.3 Maximiliano Pin <mxcpin@…> Fri, 11 May 2018 12:03:28 GMT attachment set https://svn.boost.org/trac10/ticket/13563 https://svn.boost.org/trac10/ticket/13563 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">forward_list.patch</span> </li> </ul> Ticket