Boost logo

Boost :

Subject: Re: [boost] [gil] compiler error with clang in c++11 mode
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2013-02-03 00:29:40


On Feb 2, 2013, at 9:17 AM, Christian Henning <chhenning_at_[hidden]> wrote:

> Hi there,
>
> Can someone shed some light on the following compiler errors:
>
> c:\boost\boost\gil/channel_algorithm.hpp:54:85: error: non-type
> template argument evaluates to -1, which cannot be narrowed to type
> 'unsigned long long' [-Wc++11-narrowing]
> struct unsigned_integral_max_value : public
> mpl::integral_c<UnsignedIntegralChannel,-1> {};
>
> ^
> c:\boost\boost\gil/channel_algorithm.hpp:204:19: note: in
> instantiation of template class
> 'boost::gil::detail::unsigned_integral_max_value<unsigned long long>'
> requested here
> if (src > unsigned_integral_max_value<uintmax_t>::value - div2)
>
>
> I only get those in c++11 mode. The code to trigger them is:

The error message seems pretty straightforward. The code is trying to create value of type "unsigned long long" with the value "-1".

This is (obviously) not a problem with your code, but rather a problem in Boost.Gil, related to the increased checking in Clang 3.2.
Clang is nice enough to tell you exactly how to disable this warning: add "-Wnoc++11-narrowing" to your CXXFLAGS (or however your environment lets you pass arguments to the compiler).

Alternately, you could change c:\boost\boost\gil/channel_algorithm.hpp, line 54 from:
        struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,-1> {};
to:
        struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,UnsignedIntegralChannel(-1)> {};
or, even better, to:
        struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,std::numeric_limits<UnsignedIntegralChannel>::max()> {};

Either of those should solve your problem, I think (depending on your standard library)

-- Marshall

P.S. Please open a ticket at svn.boost.org so we can be sure to fix this in a future release.


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