Boost C++ Libraries: Ticket #2685: [serialization][variant]Deserializing 'which' should check for values less than 0 https://svn.boost.org/trac10/ticket/2685 <p> In &lt;boost/serialization/variant.hpp&gt;: </p> <pre class="wiki">template&lt;class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)&gt; void load( Archive &amp; ar, boost::variant&lt;BOOST_VARIANT_ENUM_PARAMS(T)&gt;&amp; v, unsigned int version ){ int which; typedef BOOST_DEDUCED_TYPENAME boost::variant&lt;BOOST_VARIANT_ENUM_PARAMS(T)&gt;::types types; ar &gt;&gt; BOOST_SERIALIZATION_NVP(which); if(which &gt;= mpl::size&lt;types&gt;::value) // this might happen if a type was removed from the list of variant types boost::serialization::throw_exception( boost::archive::archive_exception( boost::archive::archive_exception::unsupported_version ) ); //... </pre><p> Since 'which' is an int, there should be a check and an exception thrown if which &lt; 0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2685 Trac 1.4.3 Robert Ramey Sat, 31 Jan 2009 18:28:13 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2685#comment:1 https://svn.boost.org/trac10/ticket/2685#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> how could which ever be less than zero? If this were to occur, there is a fundamental programmer error from which no recovery is possible. </p> <p> maybe an assert would be appropriate - but throwing an exception would not be. </p> <p> In fact, this makes me question the usage of throwing an exception in the current code. This means that the programmer has removed a type from the variant which is still used in some archives. At this point, one cannot not expect to be able to load old archives. </p> <p> Robert Ramey </p> Ticket