Boost logo

Boost Users :

Subject: [Boost-users] [mpl] Strange integral constant overflow warning in mpl::less_equal
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-12-18 23:08:13


This simplified version of some TMP code I am writing using mpl and
integer_traits is giving me a strange warning. I'm using VC9 and Boost 1.40:

-------------------------------------------------------------------------------------

struct ResultTypeIntegerValues
   {
   typedef boost::mpl::long_<0L> lzero;
   typedef boost::mpl::long_<boost::integer_traits<long>::const_min> lmin;
   typedef boost::mpl::less_equal<lmin,lzero>::type type;
   };

-------------------------------------------------------------------------------------

with warning message:

-------------------------------------------------------------------------------------

c:\utilities\boost\boost_1_40_0\boost\mpl\aux_\integral_wrapper.hpp(73)
: warning C4307: '-' : integral constant overflow
1>
c:\utilities\boost\boost_1_40_0\boost\mpl\aux_\preprocessed\plain\less_equal.hpp(60)
: see reference to class template instantiation 'boost::mpl::long_<N>'
being compiled
1> with
1> [
1> N=-2147483648
1> ]
1>
c:\utilities\boost\boost_1_40_0\boost\mpl\aux_\preprocessed\plain\less_equal.hpp(70)
: see reference to class template instantiation
'boost::mpl::less_equal_tag<T>' being compiled
1> with
1> [
1> T=nmspace::ResultTypeIntegerValues::lmin
1> ]
1> c:\programming\programs\xxx\yyy.h(64) : see reference to class
template instantiation 'boost::mpl::less_equal<N1,N2>' being compiled
1> with
1> [
1> N1=nmspace::ResultTypeIntegerValues::lmin,
1> N2=nmspace::ResultTypeIntegerValues::lzero
1> ]

-------------------------------------------------------------------------------------

As far as I can see I am doing a perfectly valid comparison. Is this a
minor bug in mpl or am I doing something wrong or should this warning
just be expected ?

Warning C4307 gives:

-------------------------------------------------------------------------------------

Error Message
'operator' : integral constant overflow

The operator is used in an expression that results in an integer
constant overflowing the space allocated for it. You may need to use a
larger type for the constant. A signed int holds a smaller value than an
unsigned int because the signed int uses one bit to represent the sign.

The following sample generates C4307:

// C4307.cpp
// compile with: /W2
int i = 2000000000 + 2000000000; // C4307
int j = (unsigned)2000000000 + 2000000000; // OK

int main()
{
}

-------------------------------------------------------------------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net