Boost C++ Libraries: Ticket #6546: mpl::constant_c does not support min and max values for signed types https://svn.boost.org/trac10/ticket/6546 <p> Boost.Ratio test fails on debian linux with gcc 4.6. </p> <pre class="wiki">gcc.compile.c++ ../../../bin.v2/libs/ratio/test/ratio_add_pass.test/gcc-4.6/debug/ratio_add_pass.o In file included from ../../../boost/mpl/integral_c.hpp:32:0, from ../../../boost/ratio/detail/mpl/abs.hpp:15, from ../../../boost/ratio/ratio.hpp:36, from ratio_arithmetic/ratio_add_pass.cpp:16: ../../../boost/mpl/aux_/integral_wrapper.hpp: In instantiation of ‘mpl_::integral_c&lt;long int, 9223372036854775807l&gt;’: ../../../boost/ratio/detail/mpl/abs.hpp:38:29: instantiated from ‘boost::mpl::abs_tag&lt;mpl_::integral_c&lt;long int, 9223372036854775807l&gt; &gt;’ ../../../boost/ratio/detail/mpl/abs.hpp:44:8: instantiated from ‘boost::mpl::abs&lt;mpl_::integral_c&lt;long int, 9223372036854775807l&gt; &gt;’ ../../../boost/ratio/detail/mpl/abs.hpp:58:8: instantiated from ‘boost::mpl::abs_c&lt;long int, 9223372036854775807l&gt;’ ../../../boost/ratio/ratio.hpp:79:74: instantiated from ‘const intmax_t boost::ratio&lt;9223372036854775807l, 1l&gt;::ABS_N’ ../../../boost/ratio/ratio.hpp:81:5: instantiated from ‘boost::ratio&lt;9223372036854775807l, 1l&gt;’ ../../../boost/ratio/detail/overflow_helpers.hpp:227:95: instantiated from ‘const intmax_t boost::ratio_detail::ratio_add&lt;boost::ratio&lt;9223372036854775807l, 1l&gt;, boost::ratio&lt;-0x00000000000000001l, 1l&gt; &gt;::gcd_n1_n2’ ../../../boost/ratio/detail/overflow_helpers.hpp:243:18: instantiated from ‘boost::ratio_detail::ratio_add&lt;boost::ratio&lt;9223372036854775807l, 1l&gt;, boost::ratio&lt;-0x00000000000000001l, 1l&gt; &gt;’ ../../../boost/ratio/ratio.hpp:136:8: instantiated from ‘boost::ratio_add&lt;boost::ratio&lt;9223372036854775807l, 1l&gt;, boost::ratio&lt;-0x00000000000000001l, 1l&gt; &gt;’ ratio_arithmetic/ratio_add_pass.cpp:70:37: instantiated from here ../../../boost/mpl/aux_/integral_wrapper.hpp:72:96: warning: integer overflow in expression [-Woverflow] ../../../boost/mpl/aux_/integral_wrapper.hpp:72:96: error: overflow in constant expression [-fpermissive] ../../../boost/mpl/aux_/integral_wrapper.hpp:72:96: note: in template argument for type ‘long int’ </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6546 Trac 1.4.3 Steve Robbins <smr@…> Sat, 11 Feb 2012 18:26:12 GMT <link>https://svn.boost.org/trac10/ticket/6546#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6546#comment:1</guid> <description> <p> There are similar failures for a dozen other tests, and it appears on both the Sandia and Debian gcc 4.6 testing systems; see <a href="http://www.boost.org/development/tests/release/developer/ratio.html">http://www.boost.org/development/tests/release/developer/ratio.html</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 21 Mar 2012 01:01:53 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/6546#comment:2 https://svn.boost.org/trac10/ticket/6546#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Hi, </p> <p> this is know issue on the Boost.Mpl which instantiates the next and the previous number. I've proposed a patch long time ago (since I started to use gcc-4.6) but it has not been applied. I will see what can I do. </p> Ticket viboes Wed, 21 Mar 2012 01:13:08 GMT component changed; cc set https://svn.boost.org/trac10/ticket/6546#comment:3 https://svn.boost.org/trac10/ticket/6546#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> <li><strong>component</strong> <span class="trac-field-old">ratio</span> → <span class="trac-field-new">mpl</span> </li> </ul> <p> I have found the post. See <a class="ext-link" href="http://boost.2283326.n4.nabble.com/mpl-integral-c-type-traits-integral-constant-limits-tt3042126.html#a3170972"><span class="icon">​</span>http://boost.2283326.n4.nabble.com/mpl-integral-c-type-traits-integral-constant-limits-tt3042126.html#a3170972</a>. </p> <p> Moving this to Boost.Mpl. </p> Ticket viboes Wed, 21 Mar 2012 01:18:55 GMT owner, status changed https://svn.boost.org/trac10/ticket/6546#comment:4 https://svn.boost.org/trac10/ticket/6546#comment:4 <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 Matthijs Kooijman <matthijs@…> Wed, 25 Apr 2018 09:20:04 GMT <link>https://svn.boost.org/trac10/ticket/6546#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6546#comment:5</guid> <description> <p> This bug still seems to exist (I tried today's mpl git master). The essence, as indicated in the mailing list thread above, is that <code>mpl::integral_c</code> cannot support the minimum and maximum values of signed types, since the compiler does not allow defining the prior and next values, since that would cause signed overflow which is undefined. </p> <p> The error shown in the original report is about using ratio, but this bug can be easily reproduced on by instantiating <code>mpl::integral_c</code> directly: </p> <pre class="wiki">#include &lt;boost/mpl/integral_c.hpp&gt; typedef boost::mpl::integral_c&lt;int32_t,0x7fffffff&gt;::type next_ovf_32; typedef boost::mpl::integral_c&lt;int32_t,0x80000000&gt;::type prior_ovf_32; typedef boost::mpl::integral_c&lt;int64_t,0x7fffffffffffffff&gt;::type next_ovf_64; typedef boost::mpl::integral_c&lt;int64_t,0x8000000000000000&gt;::type prior_ovf_64; </pre><p> Which leads to these errors (only one of four shown). </p> <pre class="wiki">In file included from foo.cpp:1:0: mpl/include/boost/mpl/aux_/integral_wrapper.hpp: In instantiation of ‘struct mpl_::integral_c&lt;long int, -9223372036854775808l&gt;’: foo.cpp:6:59: required from here mpl/include/boost/mpl/aux_/integral_wrapper.hpp:73:88: warning: integer overflow in expression [-Woverflow] typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (value - 1)) ) prior; ~~~~~~~^~~~ mpl/include/boost/mpl/integral_c.hpp:31:54: note: in definition of macro ‘AUX_WRAPPER_INST’ #define AUX_WRAPPER_INST(value) AUX_WRAPPER_NAME&lt; T, value &gt; ^~~~~ mpl/include/boost/mpl/aux_/integral_wrapper.hpp:73:31: note: in expansion of macro ‘BOOST_MPL_AUX_STATIC_CAST’ typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (value - 1)) ) prior; ^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from mpl/include/boost/mpl/integral_c.hpp:32:0, from foo.cpp:1: mpl/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error: overflow in constant expression [-fpermissive] typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (value - 1)) ) prior; ^~~~~ mpl/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error: overflow in constant expression [-fpermissive] mpl/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: note: in template argument for type ‘long int’ </pre><p> Solutions proposed in that thread are: </p> <ul><li>Convert to <code>intmax_t</code> before doing the +1 or -1. This is easy, but only fixes things for types smaller than <code>intmax_t</code>, leaves the problem for <code>intmax_t</code> and probably introduces the problem for <code>uintmax_t</code>. Post nr8 from Krzysztof Czainski in the above linked mailing list thread has an example implementation. </li><li>Specialize <code>integral_c</code> for these limiting values, leaving out the <code>next</code> or <code>prior</code> member. Post nr8 from Krzysztof Czainski in the above linked mailing list thread suggests this. </li><li>Remove the <code>next</code> and <code>prior</code> members from <code>integral_c</code> and use tag dispatch for them instead. Post nr4 by Vicente Botet in the above linked mailing list thread has a patch. </li></ul><p> <a class="new ticket" href="https://svn.boost.org/trac10/ticket/3779" title="#3779: Bugs: Warning using less_equal points to bug (new)">#3779</a> seems to be a duplicate of this bug. </p> </description> <category>Ticket</category> </item> <item> <author>Matthijs Kooijman <matthijs@…></author> <pubDate>Wed, 25 Apr 2018 09:20:32 GMT</pubDate> <title>version, summary changed https://svn.boost.org/trac10/ticket/6546#comment:6 https://svn.boost.org/trac10/ticket/6546#comment:6 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost Release Branch</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> <li><strong>summary</strong> <span class="trac-field-old">ratio_arithmetic/ratio_add_pass fails to compile</span> → <span class="trac-field-new">mpl::constant_c does not support min and max values for signed types</span> </li> </ul> Ticket