Boost C++ Libraries: Ticket #5658: how to get rid of nasty compiler warning in boost/property_tree/detail/rapidxml.hpp https://svn.boost.org/trac10/ticket/5658 <p> compiling e.g libs/graph/src/graphml.cpp warns ... </p> <pre class="wiki">/boost/property_tree/detail/rapidxml.hpp: In function `size_t boost::property_t ree::detail::rapidxml::internal::get_index(Ch) [with Ch = char]': ./boost/property_tree/detail/rapidxml.hpp:1413: instantiated from `static unsi gned char boost::property_tree::detail::rapidxml::xml_document&lt;Ch&gt;::whitespace_p red::test(Ch) [with Ch = char]' ./boost/property_tree/detail/rapidxml.hpp:1542: instantiated from `static void boost::property_tree::detail::rapidxml::xml_document&lt;Ch&gt;::skip(Ch*&amp;) [with Stop Pred = boost::property_tree::detail::rapidxml::xml_document&lt;char&gt;::whitespace_pr ed, int Flags = 3072, Ch = char]' ./boost/property_tree/detail/rapidxml.hpp:1377: instantiated from `void boost: :property_tree::detail::rapidxml::xml_document&lt;Ch&gt;::parse(Ch*) [with int Flags = 3072, Ch = char]' ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:116: instantiated fr om `void boost::property_tree::xml_parser::read_xml_internal(std::basic_istream&lt; typename Ptree::key_type::value_type, std::char_traits&lt;typename Ptree::key_type: :value_type&gt; &gt;&amp;, Ptree&amp;, int, const std::string&amp;) [with Ptree = boost::property_ tree::basic_ptree&lt;std::string, std::string, std::less&lt;std::string&gt; &gt;]' ./boost/property_tree/xml_parser.hpp:52: instantiated from `void boost::proper ty_tree::xml_parser::read_xml(std::basic_istream&lt;typename Ptree::key_type::value _type, std::char_traits&lt;typename Ptree::key_type::value_type&gt; &gt;&amp;, Ptree&amp;, int) [ with Ptree = boost::property_tree::ptree]' libs/graph/src/graphml.cpp:49: instantiated from here ./boost/property_tree/detail/rapidxml.hpp:317: warning: comparison is always fal se due to limited range of data type </pre><p> Caused by the template: </p> <pre class="wiki">template&lt;class Ch&gt; inline size_t get_index(const Ch c) { // If not ASCII char, its sematic is same as plain 'z' if (c &gt; 255) { return 'z'; } return c; } </pre><p> How to avoid ? Just specify additionally a user defined implementation of get_index for the "char" type : </p> <pre class="wiki"> inline size_t get_index(const char c) { return c; } template&lt;class Ch&gt; inline size_t get_index(const Ch c) { // If not ASCII char, its sematic is same as plain 'z' if (c &gt; 255) { return 'z'; } return c; } </pre><p> I checked the code size (using gcc4.0) : same and the difference of the ASM code: "same" </p> <pre class="wiki">14972c14972 &lt; cmpq (%r15), %rdi --- &gt; cmpq %rdi, (%r15) 14974c14974 &lt; jae .L3637 --- &gt; jbe .L3637 15002c15002 &lt; cmpq -16(%rsi), %rdi --- &gt; cmpq %rdi, -16(%rsi) 15004c15004 &lt; jae .L3643 --- &gt; jbe .L3643 15017c15017 &lt; cmpq -16(%rdx), %rdi --- &gt; cmpq %rdi, -16(%rdx) 15019c15019 &lt; jb .L3796 --- &gt; ja .L3796 15487c15487 --- </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5658 Trac 1.4.3 Jeremiah Willcock Wed, 29 Jun 2011 08:16:25 GMT owner, component changed https://svn.boost.org/trac10/ticket/5658#comment:1 https://svn.boost.org/trac10/ticket/5658#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Andrew Sutton</span> to <span class="trac-author">Sebastian Redl</span> </li> <li><strong>component</strong> <span class="trac-field-old">graph</span> → <span class="trac-field-new">property_tree</span> </li> </ul> Ticket Mateusz Loskot Thu, 18 Jul 2013 08:27:50 GMT cc, description changed https://svn.boost.org/trac10/ticket/5658#comment:2 https://svn.boost.org/trac10/ticket/5658#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">gcc</span> <span class="trac-author">4.0</span> <span class="trac-author">mateusz@…</span> added; <span class="trac-author">gcc 4.0</span> removed </li> <li><strong>description</strong> modified (<a href="/trac10/ticket/5658?action=diff&amp;version=2">diff</a>) </li> </ul> Ticket Sebastian Redl Fri, 14 Feb 2014 15:10:46 GMT status changed https://svn.boost.org/trac10/ticket/5658#comment:3 https://svn.boost.org/trac10/ticket/5658#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Does this still occur since the code was changed to compare against 127? </p> Ticket