[chrono][ratio][boost_1_52_0_beta1] warning in user code

I've just downloaded boost_1_52_0_beta1 and get the warning below in my user code on VC11(I'm using thread which evidently brings in the above libs). I didn't see mention of this in trac. I'm moving forward from 1.47 and from VC8 so I'm not sure if this is an indication of some project setting[s] of mine, or if it should be corrected in the lib? Thanks, Jeff 6>D:\boost_1_52_0_beta1\boost/ratio/detail/overflow_helpers.hpp(136): warning C4293: '<<' : shift count negative or too big, undefined behavior 6> D:\boost_1_52_0_beta1\boost/ratio/detail/overflow_helpers.hpp(282) : see reference to class template instantiation 'boost::ratio_detail::br_mul<X,Y>' being compiled 6> with 6> [ 6> X=0x01, 6> Y=0x01 6> ] 6> D:\boost_1_52_0_beta1\boost/ratio/ratio.hpp(155) : see reference to class template instantiation 'boost::ratio_detail::ratio_divide<R1,R2>' being compiled 6> with 6> [ 6> R1=boost::ratio<0x01,0x0989680>, 6> R2=boost::ratio<0x01,0x03e8> 6> ] 6> D:\boost_1_52_0_beta1\boost/chrono/duration.hpp(305) : see reference to class template instantiation 'boost::ratio_divide<R1,R2>' being compiled 6> with 6> [ 6> R1=boost::ratio<0x01,0x0989680>, 6> R2=boost::ratio<0x01,0x03e8> 6> ] 6> D:\boost_1_52_0_beta1\boost/chrono/duration.hpp(784) : see reference to class template instantiation 'boost::chrono::detail::duration_cast<FromDuration,ToDuration>' being compiled 6> with 6> [ 6> FromDuration=boost::chrono::duration<int_least64_t,boost::ratio<0x01,0x0989680>>, 6> ToDuration=boost::chrono::milliseconds 6> ] 6> D:\boost_1_52_0_beta1\boost/chrono/ceil.hpp(27) : see reference to function template instantiation 'boost::chrono::duration<Rep,Period> boost::chrono::duration_cast<To,int_least64_t,boost::ratio<N,D>>(const boost::chrono::duration<Rep,boost::ratio<N,D>> &)' being compiled 6> with 6> [ 6> Rep=int_least64_t, 6> Period=boost::milli, 6> To=boost::chrono::milliseconds, 6> N=0x01, 6> D=0x0989680 6> ] 6> D:\boost_1_52_0_beta1\boost/thread/win32/basic_timed_mutex.hpp(199) : see reference to function template instantiation 'To boost::chrono::ceil<boost::chrono::milliseconds,int_least64_t,boost::ratio<N,D>>(const boost::chrono::duration<Rep,Period> &)' being compiled 6> with 6> [ 6> To=boost::chrono::milliseconds, 6> N=0x01, 6> D=0x0989680, 6> Rep=int_least64_t, 6> Period=boost::ratio<0x01,0x0989680> 6> ]

Le 29/10/12 20:16, Jeff Flinn a écrit :
I've just downloaded boost_1_52_0_beta1 and get the warning below in my user code on VC11(I'm using thread which evidently brings in the above libs). I didn't see mention of this in trac. I'm moving forward from 1.47 and from VC8 so I'm not sure if this is an indication of some project setting[s] of mine, or if it should be corrected in the lib?
Thanks, Jeff
6>D:\boost_1_52_0_beta1\boost/ratio/detail/overflow_helpers.hpp(136): warning C4293: '<<' : shift count negative or too big, undefined behavior The concerned code is
static const boost::intmax_t nan = (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1)); I don't reach to see why the shift count could be negative or too big. This is used to emulate some kind of nan for integers and in principle it should not be too risky. You can try to comment the following to avoid the warning template <boost::intmax_t X, boost::intmax_t Y> class br_mul { //static const boost::intmax_t nan = // (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1)); static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min; static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max; static const boost::intmax_t a_x = mpl::abs_c<boost::intmax_t, X>::value; static const boost::intmax_t a_y = mpl::abs_c<boost::intmax_t, Y>::value; //BOOST_RATIO_STATIC_ASSERT(X != nan, BOOST_RATIO_OVERFLOW_IN_MUL, ()); //BOOST_RATIO_STATIC_ASSERT(Y != nan, BOOST_RATIO_OVERFLOW_IN_MUL, ()); BOOST_RATIO_STATIC_ASSERT(a_x <= max / a_y, BOOST_RATIO_OVERFLOW_IN_MUL, ()); public: static const boost::intmax_t value = X * Y; }; and the warning should disappear. Well note that there are other nan in the file, so them should be commented as well. You can create a ticket to track the issue in case someone finds out the possible hidden bug. Best, Vicente

On Tue, Oct 30, 2012 at 3:15 AM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
Le 29/10/12 20:16, Jeff Flinn a écrit :
I've just downloaded boost_1_52_0_beta1 and get the warning below in my user code on VC11(I'm using thread which evidently brings in the above libs). I didn't see mention of this in trac. I'm moving forward from 1.47 and from VC8 so I'm not sure if this is an indication of some project setting[s] of mine, or if it should be corrected in the lib?
Thanks, Jeff
6>D:\boost_1_52_0_beta1\boost/ratio/detail/overflow_helpers.hpp(136): warning C4293: '<<' : shift count negative or too big, undefined behavior
The concerned code is
static const boost::intmax_t nan = (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
I don't reach to see why the shift count could be negative or too big.
If I'm not mistaken, the shifted (positive) value exceeds the intmax_t value range (which is signed) but fits into uintmax_t. E.g. for 64 bit intmax_t it's 1 << 63 while intmax_t range is [-2^63; 2^63 - 1].

Le 30/10/12 07:25, Andrey Semashev a écrit :
On Tue, Oct 30, 2012 at 3:15 AM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
Le 29/10/12 20:16, Jeff Flinn a écrit :
I've just downloaded boost_1_52_0_beta1 and get the warning below in my user code on VC11(I'm using thread which evidently brings in the above libs). I didn't see mention of this in trac. I'm moving forward from 1.47 and from VC8 so I'm not sure if this is an indication of some project setting[s] of mine, or if it should be corrected in the lib?
Thanks, Jeff
6>D:\boost_1_52_0_beta1\boost/ratio/detail/overflow_helpers.hpp(136): warning C4293: '<<' : shift count negative or too big, undefined behavior The concerned code is
static const boost::intmax_t nan = (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
I don't reach to see why the shift count could be negative or too big. If I'm not mistaken, the shifted (positive) value exceeds the intmax_t value range (which is signed) but fits into uintmax_t. E.g. for 64 bit intmax_t it's 1 << 63 while intmax_t range is [-2^63; 2^63 - 1].
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
The following program int main () { std::intmax_t nan= (ULL << (sizeof(intmax_t) * 8 - 1)) ; std::intmax_t max= nan-1 ; std::intmax_t min= -max ; std::cout << std::hex << "max="<< max <<std::endl ; std::cout << std::hex << "min="<< min <<std::endl ; std::cout << std::hex << "nan="<< nan <<std::endl ; std::cout << std::dec << "max="<< max <<std::endl ; std::cout << std::dec << "min="<< min <<std::endl ; std::cout << std::dec << "nan="<< nan <<std::endl ; } prints max=7fffffffffffffff min=8000000000000001 nan=8000000000000000 max=9223372036854775807 min=-9223372036854775807 nan=-9223372036854775808 This is what I'm expecting. Maybe to avoid the warning we could replace the nan declaration by std::intmax_t nan= (ULL << (sizeof(intmax_t) * 8 - 1)) ; by std::intmax_t nan= (std::intmax_t)(1ULL << (sizeof(intmax_t) * 8 - 1)) ; Note the constant 1ULL instead of 1LL. and of course that the output is the same :) Please could you try it and see if the warning disappears? Best, Vicente

On 10/30/2012 11:56 AM, Vicente J. Botet Escriba wrote:
Le 30/10/12 07:25, Andrey Semashev a écrit :
On Tue, Oct 30, 2012 at 3:15 AM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
Le 29/10/12 20:16, Jeff Flinn a écrit :
I've just downloaded boost_1_52_0_beta1 and get the warning below in my user code on VC11(I'm using thread which evidently brings in the above libs). I didn't see mention of this in trac. I'm moving forward from 1.47 and from VC8 so I'm not sure if this is an indication of some project setting[s] of mine, or if it should be corrected in the lib?
Thanks, Jeff
6>D:\boost_1_52_0_beta1\boost/ratio/detail/overflow_helpers.hpp(136): warning C4293: '<<' : shift count negative or too big, undefined behavior The concerned code is
static const boost::intmax_t nan = (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
I don't reach to see why the shift count could be negative or too big. If I'm not mistaken, the shifted (positive) value exceeds the intmax_t value range (which is signed) but fits into uintmax_t. E.g. for 64 bit intmax_t it's 1 << 63 while intmax_t range is [-2^63; 2^63 - 1].
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
The following program
int main () { std::intmax_t nan= (ULL << (sizeof(intmax_t) * 8 - 1)) ; std::intmax_t max= nan-1 ; std::intmax_t min= -max ; std::cout << std::hex << "max="<< max <<std::endl ; std::cout << std::hex << "min="<< min <<std::endl ; std::cout << std::hex << "nan="<< nan <<std::endl ; std::cout << std::dec << "max="<< max <<std::endl ; std::cout << std::dec << "min="<< min <<std::endl ; std::cout << std::dec << "nan="<< nan <<std::endl ; }
prints
max=7fffffffffffffff min=8000000000000001 nan=8000000000000000 max=9223372036854775807 min=-9223372036854775807 nan=-9223372036854775808
This is what I'm expecting.
That's what I get on VS2012 also.
Maybe to avoid the warning we could replace the nan declaration by
std::intmax_t nan= (ULL << (sizeof(intmax_t) * 8 - 1)) ; by std::intmax_t nan= (std::intmax_t)(1ULL << (sizeof(intmax_t) * 8 - 1)) ;
Note the constant 1ULL instead of 1LL. and of course that the output is the same :)
Please could you try it and see if the warning disappears?
Yep, that clears up the warning. Thanks! static const boost::intmax_t nan = (boost::intmax_t)(1ULL << (sizeof(boost::intmax_t) * CHAR_BIT - 1)) ; The above is what I used locally. Will this get into the boost 1.52.0 release? Thanks again, Jeff

Le 30/10/12 19:56, Jeff Flinn a écrit :
On 10/30/2012 11:56 AM, Vicente J. Botet Escriba wrote:
Le 30/10/12 07:25, Andrey Semashev a écrit :
On Tue, Oct 30, 2012 at 3:15 AM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote: Maybe to avoid the warning we could replace the nan declaration by
std::intmax_t nan= (ULL << (sizeof(intmax_t) * 8 - 1)) ; by std::intmax_t nan= (std::intmax_t)(1ULL << (sizeof(intmax_t) * 8 - 1)) ;
Note the constant 1ULL instead of 1LL. and of course that the output is the same :)
Please could you try it and see if the warning disappears?
Yep, that clears up the warning. Thanks!
static const boost::intmax_t nan = (boost::intmax_t)(1ULL << (sizeof(boost::intmax_t) * CHAR_BIT - 1)) ;
The above is what I used locally.
Will this get into the boost 1.52.0 release?
Please could you create a ticket. I will commit the change after test so that there are some chances to get this fixed on release. Best, Vicente

Le 30/10/12 20:53, Vicente J. Botet Escriba a écrit :
Le 30/10/12 19:56, Jeff Flinn a écrit :
Yep, that clears up the warning. Thanks!
static const boost::intmax_t nan = (boost::intmax_t)(1ULL << (sizeof(boost::intmax_t) * CHAR_BIT - 1)) ;
The above is what I used locally.
Will this get into the boost 1.52.0 release?
Please could you create a ticket. I will commit the change after test so that there are some chances to get this fixed on release.
Committed revision 81114.
Best, Vicente

On 10/30/2012 3:56 PM, Vicente J. Botet Escriba wrote:
Le 30/10/12 20:53, Vicente J. Botet Escriba a écrit :
Le 30/10/12 19:56, Jeff Flinn a écrit :
Yep, that clears up the warning. Thanks!
static const boost::intmax_t nan = (boost::intmax_t)(1ULL << (sizeof(boost::intmax_t) * CHAR_BIT - 1)) ;
The above is what I used locally.
Will this get into the boost 1.52.0 release?
Please could you create a ticket. I will commit the change after test so that there are some chances to get this fixed on release.
Committed revision 81114.
Submitted Ticket #7616. Thanks, Jeff

On 30 October 2012 18:56, Jeff Flinn <Jeffrey.Flinn@gmail.com> wrote:
Yep, that clears up the warning. Thanks!
static const boost::intmax_t nan = (boost::intmax_t)(1ULL << (sizeof(boost::intmax_t) * CHAR_BIT - 1)) ;
The above is what I used locally.
Will this get into the boost 1.52.0 release?
If this is a warning fix, then I'm afraid it probably won't. The release branch has been closed since Monday 29th, and a warning fix isn't important enough to let through.
participants (4)
-
Andrey Semashev
-
Daniel James
-
Jeff Flinn
-
Vicente J. Botet Escriba