[cfe-dev] Error when testing clang with VC++ RTL and Boost MPL

Richard Smith richard at metafoo.co.uk
Wed Nov 13 13:54:11 PST 2013


On Wed, Nov 13, 2013 at 11:47 AM, Edward Diener <
eldlistmailingz at tropicsoft.com> wrote:

> On 11/13/2013 9:46 AM, Edward Diener wrote:
>
>> I am seeing this error when testing Boost MPL with clang using the VC++
>> RTL:
>>
>> "bitwise.cpp(40,25) :  error: non-type template argument evaluates to
>> 4294967295, which cannot be narrowed to type 'long' [-Wc++11-narrowing]
>> MPL_ASSERT_RELATION( (bitor_<_0,_ffffffff>::value), ==, 0xffffffff );"
>>
>> The typedefs are:
>>
>> typedef integral_c<unsigned int, 0> _0;
>> typedef integral_c<unsigned int, 0xffffffff> _ffffffff;
>>
>> The bitor_ in the Boost MPL is evaluating constants at compile time,
>> doing a bitwise or ('|').
>>
>> Why does clang think that 0xffffffff is a 'long' when used in the
>> comparison ? According to the C++ standard the type of 0xffffffff is the
>> first of int, unsigned int, long, unsigned long, long long, unsigned
>> long long in which its value can fit ( section 2.14.2 ). Is this a clang
>> bug ?
>>
>
> Sorry, the problem is not as I had assumed above. It is actually because
> the MPL_ASSERT_RELATION macro devolves down to a template class where the
> values are of type 'long'. Is there something in C++11 which says that
> implicit conversion of a value from an 'unsigned int' to a 'long' is
> illegal ? That is what clang is telling me but I can find no such
> restriction in the C++11 standard regarding this.


There's something like this, yes. When you have a template-parameter of
some integral type T, a template-argument for that parameter must be a
converted constant expression of type T. Converted constant expressions
don't allow narrowing conversions in the final implicit conversion from
their value to type T. And the conversion from 4294967295 to type 'long' is
a narrowing conversion, because that value does not fit in the type 'long'.
So the program is ill-formed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131113/9b78e30a/attachment.html>


More information about the cfe-dev mailing list