|
Boost : |
Subject: Re: [boost] [mpl] clang error for narrowing from unsigned int 0xffffffff to long
From: Jonathan Wakely (jwakely.boost_at_[hidden])
Date: 2013-11-14 05:09:07
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 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).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk