Boost logo

Boost :

Subject: Re: [boost] [mpl] clang error for narrowing from unsigned int 0xffffffff to long
From: Edward Diener (eldiener_at_[hidden])
Date: 2013-11-14 08:34:55


On 11/14/2013 5:09 AM, Jonathan Wakely wrote:
> On 14 November 2013 10:09, Jonathan Wakely wrote:
>> On 14 November 2013 04:22, Edward Diener wrote:
>>> On 11/13/2013 5:37 PM, Jonathan Wakely wrote:
>>>>
>>>> You can use an explicit conversion, e.g. (long)0xffffffff
>>>
>>>
>>> Or my own preference of 'static_cast<long>(0xffffffff)'. But using
>>
>> Yep, that's equivalent, and arguably clearer and cleaner.
>>
>>> '0xffffffffL' does not work. I admit that understanding the C++ Standard's
>>> different interprtetation of these two forms is beyond me.
>>
>> The expression static_cast<long>(0xffffffff) has type long, the
>> expression 0xffffffff
>
> Oops, I meant 0xffffffffL here ...
>
>> has a type given by [lex.icon], which on a
>> 32-bit system will be unsigned long. Using that expression as a
>> non-type template argument (14.3.2 [temp.arg.nontype] p5) requires no
>> conversion for the former, but requires an implicit conversion from
>> unsigned long to long in the latter case, and since the value would
>> change that is a narrowing conversion, which is not allowed in a
>> converted constant expression (5.19 [expr.const] p3).

Thanks for the full explanation.

I solved the issue with the MPL bitwise.cpp test by doing the
appropriate static_cast<long>(expression), tested it with gcc, clang,
VC++, and updated it on 'trunk'.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk