[gil] compiler error with clang in c++11 mode

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: #include <boost\gil\gil_all.hpp> int main() { return 0; } I'm using clang 3.2 on Windows with CodeBlocks. Thanks, Christian

On Feb 2, 2013, at 9:17 AM, Christian Henning <chhenning@gmail.com> 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.

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.
See ticket: https://svn.boost.org/trac/boost/ticket/7970 I fixed it in the trunk.

Hi Marshall,
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)
Just the heads up. Your std::numeric_limits<...>::max() doesn't compile with Visual Studio 2010. Thanks to Nathan, I changed it to: struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,integer_traits< UnsignedIntegralChannel>::const_max> {}; This now compiles with both clang and Visual Studio. Christian
participants (2)
-
Christian Henning
-
Marshall Clow