|
Boost : |
Subject: Re: [boost] [chrono][ratio][boost_1_52_0_beta1] warning in user code
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-10-30 11:56:20
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_at_[hidden]> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk