K-3D / k3d

The main K-3D code repository
http://www.k-3d.org/
GNU General Public License v2.0
201 stars 51 forks source link

Clang-40 compillation errors #31

Open yurivict opened 6 years ago

yurivict commented 6 years ago
In file included from /usr/local/include/boost/gil/gil_all.hpp:26:
/usr/local/include/boost/gil/channel_algorithm.hpp:54:85: error: non-type template argument evaluates to -1, which cannot be narrowed to type 'unsigned long' [-Wc++11-narrowing]
struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,-1> {};
                                                                                    ^
/usr/local/include/boost/gil/channel_algorithm.hpp:204:19: note: in instantiation of template class 'boost::gil::detail::unsigned_integral_max_value<unsigned long>' requested here
        if (src > unsigned_integral_max_value<uintmax_t>::value - div2)
                  ^
In file included from /usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.cpp:37:
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:22: error: non-constant-expression cannot be narrowed from type 'k3d::basic_rgb<double, k3d::color_traits<k3d::double_t> >::sample_type' (aka 'double') to 'GLfloat' (aka 'float') in initializer list [-Wc++11-narrowing]
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                            ^~~~~~~~~
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:22: note: insert an explicit cast to silence this issue
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                            ^~~~~~~~~
                            static_cast<GLfloat>( )
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:33: error: non-constant-expression cannot be narrowed from type 'k3d::basic_rgb<double, k3d::color_traits<k3d::double_t> >::sample_type' (aka 'double') to 'GLfloat' (aka 'float') in initializer list [-Wc++11-narrowing]
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                                       ^~~~~~~~~~~
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:33: note: insert an explicit cast to silence this issue
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                                       ^~~~~~~~~~~
                                       static_cast<GLfloat>( )
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:46: error: non-constant-expression cannot be narrowed from type 'k3d::basic_rgb<double, k3d::color_traits<k3d::double_t> >::sample_type' (aka 'double') to 'GLfloat' (aka 'float') in initializer list [-Wc++11-narrowing]
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                                                    ^~~~~~~~~~
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:46: note: insert an explicit cast to silence this issue
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                                                    ^~~~~~~~~~
                                                    static_cast<GLfloat>( )
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:58: error: non-constant-expression cannot be narrowed from type 'double' to 'GLfloat' (aka 'float') in initializer list [-Wc++11-narrowing]
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                                                                ^~~~~
/usr/ports/graphics/k3d/work/k3d-k3d-0.8.0.6/k3dsdk/utility_gl.h:107:58: note: insert an explicit cast to silence this issue
        GLfloat color[] = { Color.red, Color.green, Color.blue, Alpha };
                                                                ^~~~~
                                                                static_cast<GLfloat>( )
yurivict commented 6 years ago

@barche Jan, are you able to fix these? The FreeBSD port for k3d has been deleted some while ago. I am trying to restore it now. But it doesn't build with clang-40. Are you able to fix all clang-40 build errors?

Thanks, Yuri

barche commented 6 years ago

Hi Yuri,

Sorry for the slow reply, I haven't build K-3D using clang for some years. I don't have a freeBSD system to test this on, but I could try building on my Mac and see if I can reproduce this. I think in this case adding explicit casts is the solution, e.g.

GLfloat color[] = { static_cast<float>(Color.red), static_cast<float>(Color.green), static_cast<float>(Color.blue), static_cast<float>(Alpha) };
yurivict commented 6 years ago

Yes, this would have been great if you could fix clang issues on any system. The rest of the differences if any shouldn't be too hard to accommodate.

barche commented 6 years ago

OK, so it builds using clang 5 on Linux now, hopefully this also gets you further on FreeBSD!

yurivict commented 6 years ago

It still breaks for me here:

In file included from /usr/local/include/boost/gil/gil_all.hpp:26:
/usr/local/include/boost/gil/channel_algorithm.hpp:54:85: error: non-type template argument evaluates to -1, which cannot be narrowed to type 'unsigned long' [-Wc++11-narrowing]
struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,-1> {};
                                                                                    ^
/usr/local/include/boost/gil/channel_algorithm.hpp:204:19: note: in instantiation of template class 'boost::gil::detail::unsigned_integral_max_value<unsigned long>' requested here
        if (src > unsigned_integral_max_value<uintmax_t>::value - div2)
                  ^

Also, you should remove all register keywords. Latest developments in compiles rendered it useless, and it only causes warnings now.

clang-5.0.0

barche commented 6 years ago

Is that the complete error? It is situated completely in boost, on my system it selects the gil library included in K-3D and then it compiles.

yurivict commented 6 years ago

This line https://github.com/K-3D/k3d/blob/master/k3dsdk/bitmap.h#L36 includes gil_all.hpp that isn't in the project.

It can't use the include from the pre-installed boost, but override only the gil package. This is just too convoluted. :-)

barche commented 6 years ago

Actually, what is added is an extension to gil, so files from the system boost are still needed. I can't reproduce this error on my linux system, can you please post the full error, including the location in the K-3D code that triggers this? If there is no instantiation in K-3D, I guess this is really a bug in boost, I'm using version 1.66 but the referred lines are the same.

yurivict commented 6 years ago

Here is one full instance of this error:

--- k3dsdk/CMakeFiles/k3dsdk.dir/utility_gl.cpp.o ---
In file included from /usr/ports/graphics/k3d/work/k3d-7111d0e/k3dsdk/utility_gl.cpp:37:
In file included from /usr/ports/graphics/k3d/work/k3d-7111d0e/k3dsdk/utility_gl.h:28:
In file included from /usr/ports/graphics/k3d/work/k3d-7111d0e/k3dsdk/bitmap.h:36:
In file included from /usr/local/include/boost/gil/gil_all.hpp:26:
/usr/local/include/boost/gil/channel_algorithm.hpp:54:85: error: non-type template argument evaluates to -1, which cannot be narrowed to type 'unsigned long' [-Wc++11-narrowing]
struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,-1> {};
                                                                                    ^
/usr/local/include/boost/gil/channel_algorithm.hpp:204:19: note: in instantiation of template class 'boost::gil::detail::unsigned_integral_max_value<unsigned long>' requested here
        if (src > unsigned_integral_max_value<uintmax_t>::value - div2)
                  ^
barche commented 6 years ago

OK, so it appears there is no instantiation happening from K-3D. Can you try compiling and posting the output of the following test program:

#include <iostream>
#include <typeinfo>
#include <boost/gil/gil_all.hpp>
int main()
{
  std::cout << typeid(boost::uintmax_t).name() << std::endl;
  std::cout << typeid(uint64_t).name() << std::endl;
  return 0;
}

I compiled it with

clang++ -o test test.cpp
yurivict commented 6 years ago
$ ./test 
m
m
barche commented 6 years ago

Can you try adding the following in bitmap.h, just before the existing channel_converter_unsigned:

template <> struct channel_converter_unsigned<bits32f,uintmax_t> : public std::unary_function<bits32f,bits32f>
{
    uintmax_t operator()(bits32f   x) const { return uintmax_t(static_cast<float>(x)); }
};
yurivict commented 6 years ago

With channel_converter_unsigned<bits32f,uintmax_t> it breaks the same way.

barche commented 6 years ago

Well then, if the error has absolutely no indication of what part of K-3D is causing this, then I'm out of ideas...

yurivict commented 6 years ago

To me, it looks like boost tries to instantiate its own template with the wrong argument: for mpl::integral_c, the base of unsigned_integral_max_value, it supplies -1 when a type is expected. But since they both are in the boost headers, it looks like an internal boost error.

barche commented 6 years ago

Yes, you could try replacing the -1 with static_cast<UnsignedIntegralChannel>(-1) in your boost header, see how far that gets us. If it works that way, it's probably best to submit a bug report to Boost

yurivict commented 6 years ago

Substituting with static_cast<UnsignedIntegralChannel>(-1) indeed helped.

I submitted the ticket to boost: https://svn.boost.org/trac10/ticket/13397

mloskot commented 6 years ago

FYI, this issue has been fixed in GIL released in Boost 1.68 ​https://github.com/boostorg/gil/commit/18eacb424baf69852bb24858e1b3a5c86e1f9033 So, the https://svn.boost.org/trac10/ticket/13397 has just been closed.

Thank you for reporting the issue anyway.