Boost C++ Libraries: Ticket #7873: C4244 in basic_binary_iprimitive.hpp due to std::size_t and std::streamsize type difference https://svn.boost.org/trac10/ticket/7873 <p> With Visual Studio 2010 a C4244 warning appears in basic_binary_iprimitive.hpp. </p> <p> boost/archive/basic_binary_iprimitive.hpp(181): warning C4244: 'argument' : conversion from 'std::streamsize' to 'size_t', possible loss of data </p> <p> The offending line is the last one in the function, with (count - s) </p> <pre class="wiki">template&lt;class Archive, class Elem, class Tr&gt; inline void basic_binary_iprimitive&lt;Archive, Elem, Tr&gt;::load_binary( void *address, std::size_t count ){ // note: an optimizer should eliminate the following for char files BOOST_ASSERT( static_cast&lt;std::streamsize&gt;(count / sizeof(Elem)) &lt;= boost::integer_traits&lt;std::streamsize&gt;::const_max ); std::streamsize s = static_cast&lt;std::streamsize&gt;(count / sizeof(Elem)); std::streamsize scount = m_sb.sgetn( static_cast&lt;Elem *&gt;(address), s ); if(scount != s) boost::serialization::throw_exception( archive_exception(archive_exception::input_stream_error) ); // note: an optimizer should eliminate the following for char files BOOST_ASSERT(count % sizeof(Elem) &lt;= boost::integer_traits&lt;std::streamsize&gt;::const_max); s = static_cast&lt;std::streamsize&gt;(count % sizeof(Elem)); if(0 &lt; s){ // if(is.fail()) // boost::serialization::throw_exception( // archive_exception(archive_exception::stream_error) // ); Elem t; scount = m_sb.sgetn(&amp; t, 1); if(scount != 1) boost::serialization::throw_exception( archive_exception(archive_exception::input_stream_error) ); std::memcpy(static_cast&lt;char*&gt;(address) + (count - s), &amp;t, s); } } </pre><p> where count is a passed-in std::size_t and s is a local std::streamsize. </p> <p> Ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3755" title="#3755: Patches: Warning comparison between signed and unsigned integer in asserts (closed: fixed)">#3755</a> discusses a related issue in the asserts where a signed/unsigned comparison took place. This was resolved by a static_cast in the assert. </p> <p> For Visual Studio 2010, x86, and both Release and Debug, the following <strong>effective</strong> typedefs apply </p> <pre class="wiki">typedef __int64 streamsize; typedef _unsigned int size_t; </pre><p> Since s is set by count, there does not seen to be a risk of overflowing s. Is there any way to prevent the warning? </p> <p> I check the current trunk and the issue would still exist. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7873 Trac 1.4.3 anonymous Wed, 30 Jan 2013 17:59:43 GMT <link>https://svn.boost.org/trac10/ticket/7873#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7873#comment:1</guid> <description> <p> I'm also experiencing this. Really annoying warning! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 06 Feb 2013 20:33:36 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7873#comment:2 https://svn.boost.org/trac10/ticket/7873#comment:2 <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">fixed</span> </li> </ul> Ticket yochait@… Tue, 23 Apr 2013 07:02:44 GMT <link>https://svn.boost.org/trac10/ticket/7873#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7873#comment:3</guid> <description> <p> An easy "fix" for this if you don't have a fixed version of boost:<br /> Just ignore the warnings in the specific files. </p> <p> #pragma warning (push) <br /> #pragma warning( disable : 4244 ) <br /> </p> <p> #include &lt;boost/archive/binary_oarchive.hpp&gt; <br /> #include &lt;boost/archive/binary_iarchive.hpp&gt; <br /> </p> <p> #pragma warning (pop) <br /> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 27 Mar 2014 20:14:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7873#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7873#comment:4</guid> <description> <p> Same issue in dynamic_bitset.hpp in Boost 1_55_0 </p> </description> <category>Ticket</category> </item> </channel> </rss>