Boost C++ Libraries: Ticket #9647: BOOST_MPL_ASSERT_RELATION fails to properly handle unsigned types https://svn.boost.org/trac10/ticket/9647 <p> boost/integer_traits.hpp contains the following </p> <pre class="wiki">template&lt;&gt; class integer_traits&lt;unsigned long&gt; : public std::numeric_limits&lt;unsigned long&gt;, public detail::integer_traits_base&lt;unsigned long, 0, ULONG_MAX&gt; { }; </pre><p> Problem is that, at least on Clang ULONG_MAX resolves to (through &lt;limits.h&gt;) to be </p> <pre class="wiki">#define ULONG_MAX (__LONG_MAX__ *2UL+1UL) </pre><p> But when <span class="underline">LONG_MAX</span> resolves to long and the rules of arithmetic promotion result in the expression <span class="underline">LONG_MAX</span> *2UL+1UL being a long rather than unsigned long. This causes some funky behavior in cases like: </p> <pre class="wiki">BOOST_MPL_ASSERT_RELATION( (boost::integer_traits&lt;unsigned long&gt;::const_max), &gt;, (boost::integer_traits&lt;unsigned char&gt;::const_max) ); </pre><p> which fails to compile with "Non-type template argument evaluates to 4294967295, which cannot be narrowed to type 'long' </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9647 Trac 1.4.3 viboes Sun, 25 Jan 2015 15:22:07 GMT summary changed https://svn.boost.org/trac10/ticket/9647#comment:1 https://svn.boost.org/trac10/ticket/9647#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">boost_MPL_ASSERT_RELATION fails to properly handle unsigned types</span> → <span class="trac-field-new">BOOST_MPL_ASSERT_RELATION fails to properly handle unsigned types</span> </li> </ul> <p> Is this a problem with Clang, Boost.Mpl or Boost.Integer library? </p> Ticket viboes Sun, 25 Jan 2015 15:47:26 GMT owner, status changed https://svn.boost.org/trac10/ticket/9647#comment:2 https://svn.boost.org/trac10/ticket/9647#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Daryle Walker</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Robert Ramey Sun, 22 Mar 2015 22:41:09 GMT <link>https://svn.boost.org/trac10/ticket/9647#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9647#comment:3</guid> <description> <p> I'm thinking that this is libc++ version of limits.h </p> <p> perhaps this is not the correct place to report this. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Mon, 23 Mar 2015 18:23:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9647#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9647#comment:4</guid> <description> <p> I looked into this a little bit more. </p> <p> First of all, my original guess about problematic type promotions was wrong - I don't think there is any issue with libc++ or anything else in the standard library. </p> <p> The following test program illustrates my </p> <pre class="wiki">#include &lt;boost/integer_traits.hpp&gt; #include &lt;boost/mpl/assert.hpp&gt; BOOST_MPL_ASSERT_RELATION( (boost::integer_traits&lt;unsigned long&gt;::const_max), &gt;, (boost::integer_traits&lt;unsigned char&gt;::const_max) ); // compile error under clang enum { x = ( (boost::integer_traits&lt;unsigned long&gt;::const_max) &gt; (boost::integer_traits&lt;unsigned char&gt;::const_max) ) }; // compiles OK - can't figure out why constexpr bool result = ( (boost::integer_traits&lt;unsigned long&gt;::const_max) &gt; (boost::integer_traits&lt;unsigned char&gt;::const_max) ); // compiles fine static_assert(result, "compilation error"); int main(int argc, char * argv[]){ return ! (boost::integer_traits&lt;unsigned long&gt;::const_max &gt; boost::integer_traits&lt;unsigned char&gt;::const_max); } </pre><p> So I believe this is an issue with MPL_ASSERT_RELATION. I've believe the problem is found in boost/mpl/assert.hpp at the line <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/329" title="#329: Support Requests: Boost Library Unknown compiler version (closed: Out of Date)">#329</a>: It's probably deeper than this but I didn't trace it further </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 04 Apr 2015 21:29:22 GMT</pubDate> <title>component changed https://svn.boost.org/trac10/ticket/9647#comment:5 https://svn.boost.org/trac10/ticket/9647#comment:5 <ul> <li><strong>component</strong> <span class="trac-field-old">integer</span> → <span class="trac-field-new">mpl</span> </li> </ul> Ticket viboes Sat, 04 Apr 2015 21:29:55 GMT owner, status changed https://svn.boost.org/trac10/ticket/9647#comment:6 https://svn.boost.org/trac10/ticket/9647#comment:6 <ul> <li><strong>owner</strong> changed from <span class="trac-author">viboes</span> to <span class="trac-author">Aleksey Gurtovoy</span> </li> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket