Boost C++ Libraries: Ticket #2558: Unnecessary conversion warning in lexical_cast https://svn.boost.org/trac10/ticket/2558 <p> When trying to compile the following against <a class="changeset" href="https://svn.boost.org/trac10/changeset/50058" title="added Vardan Akopian's bindings for gbtrf / gbtrs ">r50058</a> with g++ -Wconversion: </p> <pre class="wiki">#include &lt;boost/lexical_cast.hpp&gt; #include &lt;string&gt; using namespace boost; using namespace std; int main() { lexical_cast&lt;string&gt;(3); return 0; } </pre><p> I get: </p> <pre class="wiki">/home/yang/work/boost/boost/lexical_cast.hpp: In function ‘CharT* boost::detail::lcast_put_unsigned(T, CharT*) [with Traits = std::char_traits&lt;char&gt;, T = unsigned int, CharT = char]’: /home/yang/work/boost/boost/lexical_cast.hpp:848: instantiated from ‘bool boost::detail::lexical_stream_limited_src&lt;CharT, Base, Traits&gt;::operator&lt;&lt;(int) [with CharT = char, Base = boost::detail::lexical_streambuf_fake, Traits = std::char_traits&lt;char&gt;]’ /home/yang/work/boost/boost/lexical_cast.hpp:1142: instantiated from ‘Target boost::detail::lexical_cast(typename boost::call_traits&lt;Source&gt;::param_type, CharT*, size_t) [with Target = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, Source = int, bool Unlimited = false, CharT = boost::lexical_cast::char_type]’ /home/yang/work/boost/boost/lexical_cast.hpp:1166: instantiated from ‘Target boost::lexical_cast(const Source&amp;) [with Target = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, Source = int]’ blah.cc:6: instantiated from here /home/yang/work/boost/boost/lexical_cast.hpp:510: warning: conversion to ‘char’ from ‘int’ may alter its value /home/yang/work/boost/boost/lexical_cast.hpp:848: instantiated from ‘bool boost::detail::lexical_stream_limited_src&lt;CharT, Base, Traits&gt;::operator&lt;&lt;(int) [with CharT = char, Base = boost::detail::lexical_streambuf_fake, Traits = std::char_traits&lt;char&gt;]’ /home/yang/work/boost/boost/lexical_cast.hpp:1142: instantiated from ‘Target boost::detail::lexical_cast(typename boost::call_traits&lt;Source&gt;::param_type, CharT*, size_t) [with Target = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, Source = int, bool Unlimited = false, CharT = boost::lexical_cast::char_type]’ /home/yang/work/boost/boost/lexical_cast.hpp:1166: instantiated from ‘Target boost::lexical_cast(const Source&amp;) [with Target = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, Source = int]’ blah.cc:6: instantiated from here /home/yang/work/boost/boost/lexical_cast.hpp:512: warning: conversion to ‘char’ from ‘int’ may alter its value /home/yang/work/boost/boost/lexical_cast.hpp:536: warning: conversion to ‘char’ from ‘int’ may alter its value </pre><p> It seems this is because the header is using CHAR_MAX as-is and expecting it to be a char. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2558 Trac 1.4.3 nasonov Sat, 12 Sep 2009 22:33:07 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2558#comment:1 https://svn.boost.org/trac10/ticket/2558#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">worksforme</span> </li> </ul> <p> Not reproducible neither with gcc 3.4.6 nor 4.1.3 on NetBSD 5.99.17 (-current). Please submit a patch. </p> Ticket anonymous Mon, 21 Jan 2013 06:30:12 GMT status, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/2558#comment:2 https://svn.boost.org/trac10/ticket/2558#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">worksforme</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.38.0</span> → <span class="trac-field-new">Boost 1.53.0</span> </li> </ul> <p> This above code is either broken again or still broken with g++ 4.7. </p> <pre class="wiki">$ g++-fsf-4.7 -I/sw/include/ -Wconversion Foo.cpp In file included from Foo.cpp:1:0: /sw/include/boost/lexical_cast.hpp: In instantiation of 'CharT* boost::detail::lcast_put_unsigned(T, CharT*) [with Traits = std::char_traits&lt;char&gt;; T = unsigned int; CharT = char]': /sw/include/boost/lexical_cast.hpp:860:13: required from 'bool boost::detail::lexical_stream_limited_src&lt;CharT, Base, Traits&gt;::operator&lt;&lt;(int) [with CharT = char; Base = boost::detail::lexical_streambuf_fake; Traits = std::char_traits&lt;char&gt;]' /sw/include/boost/lexical_cast.hpp:1151:13: required from 'Target boost::detail::lexical_cast(typename boost::call_traits&lt;Source&gt;::param_type, CharT*, std::size_t) [with Target = std::basic_string&lt;char&gt;; Source = int; bool Unlimited = false; CharT = char; typename boost::call_traits&lt;Source&gt;::param_type = const int; std::size_t = long unsigned int]' /sw/include/boost/lexical_cast.hpp:1174:77: required from 'Target boost::lexical_cast(const Source&amp;) [with Target = std::basic_string&lt;char&gt;; Source = int]' Foo.cpp:6:25: required from here /sw/include/boost/lexical_cast.hpp:522:72: warning: conversion to 'char' from 'int' may alter its value [-Wconversion] /sw/include/boost/lexical_cast.hpp:524:74: warning: conversion to 'char' from 'int' may alter its value [-Wconversion] /sw/include/boost/lexical_cast.hpp:548:25: warning: conversion to 'char' from 'int' may alter its value [-Wconversion] </pre> Ticket anonymous Mon, 21 Jan 2013 06:33:13 GMT <link>https://svn.boost.org/trac10/ticket/2558#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2558#comment:3</guid> <description> <p> That was 1.46.1 by the way. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Sun, 03 Feb 2013 07:42:01 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/2558#comment:4 https://svn.boost.org/trac10/ticket/2558#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">nasonov</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket Antony Polukhin Sun, 03 Feb 2013 09:20:34 GMT <link>https://svn.boost.org/trac10/ticket/2558#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2558#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/82695" title="Fixed as many -Wconversion warnings in lexical cast and tests as ...">[82695]</a>) Fixed as many -Wconversion warnings in lexical cast and tests as possible (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2558" title="#2558: Bugs: Unnecessary conversion warning in lexical_cast (closed: fixed)">#2558</a>) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Sun, 24 Feb 2013 08:31:19 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2558#comment:6 https://svn.boost.org/trac10/ticket/2558#comment:6 <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/83114" title="Merge from trunk: * Silence some buggy VS warnings (fixes #7949) * Fix ...">[83114]</a>) Merge from trunk: </p> <ul><li>Silence some buggy VS warnings (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7949" title="#7949: Bugs: Level 4 Warnings with VS2005 (closed: fixed)">#7949</a>) </li><li>Fix -Wconversion warnings (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2558" title="#2558: Bugs: Unnecessary conversion warning in lexical_cast (closed: fixed)">#2558</a>) </li><li>Added support for int128 conversions (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7909" title="#7909: Feature Requests: Add support for conversions of int128 types (closed: fixed)">#7909</a>) </li></ul> Ticket Antony Polukhin Sun, 24 Feb 2013 08:32:50 GMT milestone changed https://svn.boost.org/trac10/ticket/2558#comment:7 https://svn.boost.org/trac10/ticket/2558#comment:7 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.53.0</span> → <span class="trac-field-new">Boost 1.54.0</span> </li> </ul> Ticket