Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6546: ratio_arithmetic/ratio_add_pass fails to compile
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-04-25 09:20:04
#6546: ratio_arithmetic/ratio_add_pass fails to compile
-----------------------------------+------------------------------
Reporter: smr@⦠| Owner: Aleksey Gurtovoy
Type: Bugs | Status: new
Milestone: To Be Determined | Component: mpl
Version: Boost Release Branch | Severity: Problem
Resolution: | Keywords:
-----------------------------------+------------------------------
Comment (by Matthijs Kooijman <matthijs@â¦>):
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
{{{mpl::integral_c}}} 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.
The error shown in the original report is about using ratio, but this bug
can be easily reproduced on by instantiating {{{mpl::integral_c}}}
directly:
{{{
#include <boost/mpl/integral_c.hpp>
typedef boost::mpl::integral_c<int32_t,0x7fffffff>::type next_ovf_32;
typedef boost::mpl::integral_c<int32_t,0x80000000>::type prior_ovf_32;
typedef boost::mpl::integral_c<int64_t,0x7fffffffffffffff>::type
next_ovf_64;
typedef boost::mpl::integral_c<int64_t,0x8000000000000000>::type
prior_ovf_64;
}}}
Which leads to these errors (only one of four shown).
{{{
In file included from foo.cpp:1:0:
mpl/include/boost/mpl/aux_/integral_wrapper.hpp: In instantiation of
âstruct mpl_::integral_c<long int, -9223372036854775808l>â:
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< T, value >
^~~~~
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â
}}}
Solutions proposed in that thread are:
- Convert to {{{intmax_t}}} before doing the +1 or -1. This is easy, but
only fixes things for types smaller than {{{intmax_t}}}, leaves the
problem for {{{intmax_t}}} and probably introduces the problem for
{{{uintmax_t}}}. Post nr8 from Krzysztof Czainski in the above linked
mailing list thread has an example implementation.
- Specialize {{{integral_c}}} for these limiting values, leaving out the
`next` or `prior` member. Post nr8 from Krzysztof Czainski in the above
linked mailing list thread suggests this.
- Remove the `next` and `prior` members from `integral_c` and use tag
dispatch for them instead. Post nr4 by Vicente Botet in the above linked
mailing list thread has a patch.
#3779 seems to be a duplicate of this bug.
-- Ticket URL: <https://svn.boost.org/trac10/ticket/6546#comment:5> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2018-04-25 09:26:16 UTC