Boost C++ Libraries: Ticket #4184: compiler warnings in VC9 https://svn.boost.org/trac10/ticket/4184 <p> lexical_cast issues the following warning under VC8 and higher at warning level 3: </p> <p> e:\develop\libs\boost_1_42_0\boost\lexical_cast.hpp(1151) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data </p> <p> The code seems to have been restructured a bit to fix ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3198" title="#3198: Bugs: compiler warnings in VC9 (closed: duplicate)">#3198</a> (or <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1791" title="#1791: Patches: fix warning on MSVC warning level 4 (closed: fixed)">#1791</a>), a block of disabled warnings (currently '4701' and '4702') has been introduced. </p> <p> The problem can be worked-around when adding a statement to disable the warning '4267' in the same block. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4184 Trac 1.4.3 Steven Watanabe Sat, 15 May 2010 02:40:17 GMT <link>https://svn.boost.org/trac10/ticket/4184#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4184#comment:1</guid> <description> <p> I can't reproduce the problem with VC 2010. Can you provide a test case? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 17 May 2010 07:40:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4184#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4184#comment:2</guid> <description> <p> I did a simple test with VC8 and VC10 from command line "cl.exe" like this </p> <p> lex_test.cpp: </p> <hr /> <p> #include &lt;...&gt; void main() { </p> <blockquote> <p> size_t num = 12345; std::string num_to_string = boost::lexical_cast&lt;std::string&gt;( num ); </p> </blockquote> <p> } </p> <hr /> <p> and it didn't show up, so I digged deeper and found out that the warning appears to be caused by the 64 bit warning switch /(Wp64), i.e. when you compile with </p> <p> cl lex_test.cpp /I&lt;boost_1_42_0-dir&gt; /EHsc /W4 /Wp64 </p> <p> This happens with both tested VC compilers from command line, as well as in Win32 projects created with the VC8 (2005) Wizard. When using the command line, VC10 indicates the option "Wp64" as deprecated, and without the switch, it compiles without warning (as does VC8). However, all Win32 projects seem to have the switch enabled in VC8. </p> <p> Not sure if there is a real 'size_t' conversion issue on 64-bit targets or if it can be ignored. </p> <p> As VC reports the warning (like all problems with templates) in an ugly multi-line warning, the compile report gets quite verbose on projects which make heavy use of lexical_cast with the Wp64 option enabled when switching from e.g. boost 1.36.0 to 1.42.0. </p> <p> As there is already a disabled-warning-block-for-MSVC in the lexical_cast source at this place, I escaped from the warning report hell in my private local boost copy by excluding this warning as well. </p> <p> If you decide the source to be left unchanged, can you confirm there is no 64-bit issue? </p> </description> <category>Ticket</category> </item> <item> <author>admin@…</author> <pubDate>Fri, 11 Jun 2010 06:04:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4184#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4184#comment:3</guid> <description> <p> While working on a patch today for another issue (link) in the same function in boost::lexical_cast, I came across this and decided to do some digging. I'm pretty confident that there is no actual 64-bit issue, and that this warning can be ignored safely. </p> <p> <strong>From MSDN (<a class="ext-link" href="http://msdn.microsoft.com/en-us/library/6kck0s93%28VS.80%29.aspx"><span class="icon">​</span>http://msdn.microsoft.com/en-us/library/6kck0s93%28VS.80%29.aspx</a>):</strong> </p> <p> <em>In this situation, C4267 is caused by a limitation in /Wp64 warnings. On x86, std::cout&lt;&lt;range_index resolves to the overload of operator&lt;&lt; that accepts an unsigned int, since size_t is an unsigned int on Win32. C4267 occurs because you passed a size_t as an unsigned int argument, which would cause truncation on Win64 where size_t is 64-bit, but unsigned int is still 32-bit. This can be ignored because if you compiled for Win64, std::cout&lt;&lt;range_index would resolve to the overload of operator&lt;&lt; that accepts an <code>unsigned __int64</code>, since that's what type size_t is on Win64. The 32-bit compiler doesn't notice, so it warns.</em> </p> <p> This warning isn't raised by std::cout, but I believe the situation described by MSDN is applies to this warning. lexical_stream_limited_src is a stream wrapper template class (derived from std::basic_streambuf), and it has an operator&lt;&lt; overload that accepts an unsigned int. It also has an operator&lt;&lt; that takes an <code>unsigned __int64</code> if compiled for Win64. </p> <p> <strong>Source of the issue in lexical_cast.hpp (boost 1.42):</strong> </p> <pre class="wiki"> template&lt; typename Target , typename Source , bool Unlimited // string representation of Source is unlimited , typename CharT &gt; Target lexical_cast( BOOST_DEDUCED_TYPENAME boost::call_traits&lt;Source&gt;::param_type arg, CharT* buf, std::size_t src_len) { typedef BOOST_DEDUCED_TYPENAME deduce_char_traits&lt;CharT,Target,Source&gt;::type traits; typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c&lt; lcast_streambuf_for_target&lt;Target&gt;::value || lcast_streambuf_for_source&lt;Source&gt;::value , std::basic_streambuf&lt;CharT&gt; , lexical_streambuf_fake &gt;::type base; BOOST_DEDUCED_TYPENAME boost::mpl::if_c&lt; Unlimited , detail::lexical_stream&lt;Target,Source,traits&gt; , detail::lexical_stream_limited_src&lt;CharT,base,traits&gt; &gt;::type interpreter(buf, buf + src_len); Target result; if(!(interpreter &lt;&lt; arg &amp;&amp; interpreter &gt;&gt; result)) // line 1151, as of boost 1.42 when this issue was reported BOOST_LCAST_THROW_BAD_CAST(Source, Target); return result; } </pre><p> <strong>Relevant declarations in lexical_stream_limited_src (boost 1.42; the full declaration starts at line 660):</strong> </p> <pre class="wiki"> // String representation of Source has an upper limit. template&lt; class CharT // a result of widest_char transformation , class Base // lexical_streambuf_fake or basic_streambuf&lt;CharT&gt; , class Traits // usually char_traits&lt;CharT&gt; &gt; class lexical_stream_limited_src : public Base { /* truncated */ bool operator&lt;&lt;(unsigned short); bool operator&lt;&lt;(unsigned int); // bool operator&lt;&lt;(unsigned long); #if defined(BOOST_HAS_LONG_LONG) bool operator&lt;&lt;(boost::ulong_long_type); bool operator&lt;&lt;(boost::long_long_type ); #elif defined(BOOST_HAS_MS_INT64) bool operator&lt;&lt;(unsigned __int64); bool operator&lt;&lt;( __int64); #endif /* truncated */ } </pre><p> I've submitted a patch (<a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/4334"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/4334</a>) that should resolve this. I don't have access to MSVC or a Windows machine (nor the experience for it to matter), so hopefully someone more knowledgable than me can verify if I'm correct about this being ignorable. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 11 Jun 2010 16:12:48 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4184#comment:4 https://svn.boost.org/trac10/ticket/4184#comment:4 <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> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/62806" title="Supress MSVC /Wp64 warnings. Fixes #4184">[62806]</a>) Supress MSVC /Wp64 warnings. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4184" title="#4184: Bugs: compiler warnings in VC9 (closed: fixed)">#4184</a> </p> Ticket