boostorg / mpl

Boost.org mpl module
http://boost.org/libs/mpl
Boost Software License 1.0
52 stars 78 forks source link

compilation fails with clang 16 when enumerated type used in AUX_WRAPPER_INST #74

Closed yuvalif closed 2 years ago

yuvalif commented 2 years ago

using boost 1.79 and clang 16 I get the following compilation errors when trying to define the next/prev types of an enumerated type in the range [0,3]:

In file included from libs/python/src/converter/builtin_converters.cpp:21:
In file included from ./boost/cast.hpp:18:
In file included from ./boost/numeric/conversion/cast.hpp:33:
In file included from ./boost/numeric/conversion/converter.hpp:13:
In file included from ./boost/numeric/conversion/conversion_traits.hpp:13:
In file included from ./boost/numeric/conversion/detail/conversion_traits.hpp:18:
In file included from ./boost/numeric/conversion/detail/int_float_mixture.hpp:19:
In file included from ./boost/mpl/integral_c.hpp:32:
./boost/mpl/aux_/integral_wrapper.hpp:73:31: error: integer value -1 is outside the valid range of values [0, 3] for this enumeration type [-Wenum-constexpr-conversion]
./boost/mpl/aux_/static_cast.hpp:24:47: note: expanded from macro 'BOOST_MPL_AUX_STATIC_CAST'
#   define BOOST_MPL_AUX_STATIC_CAST(T, expr) static_cast<T>(expr)
In file included from libs/python/src/converter/builtin_converters.cpp:21:
In file included from ./boost/cast.hpp:18:
In file included from ./boost/numeric/conversion/cast.hpp:33:
In file included from ./boost/numeric/conversion/converter.hpp:13:
In file included from ./boost/numeric/conversion/conversion_traits.hpp:13:
In file included from ./boost/numeric/conversion/detail/conversion_traits.hpp:18:
In file included from ./boost/numeric/conversion/detail/int_float_mixture.hpp:19:
In file included from ./boost/mpl/integral_c.hpp:32:
./boost/mpl/aux_/integral_wrapper.hpp:72:31: error: integer value 4 is outside the valid range of values [0, 3] for this enumeration type [-Wenum-constexpr-conversion]
    typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (value + 1)) ) next;
                              ^
./boost/mpl/aux_/static_cast.hpp:24:47: note: expanded from macro 'BOOST_MPL_AUX_STATIC_CAST'
#   define BOOST_MPL_AUX_STATIC_CAST(T, expr) static_cast<T>(expr)
                                              ^
pdimov commented 2 years ago

See https://github.com/boostorg/mpl/issues/69 and https://github.com/boostorg/numeric_conversion/issues/24.

yuvalif commented 2 years ago

@pdimov, thanks! will close in favor of the other one.

dkrejsa commented 1 year ago

Hi, Compiling Boost 1.81 with clang 16.0.0, I still see this sort of error:

clang-vxworks.compile.c++ ../bin.v2/libs/numeric/conversion/test/traits_test.test/clang-vxworks-16.0.0.1/debug/static-only-on/target-os-vxworks/traits_test.o In file included from ../libs/numeric/conversion/test/traits_test.cpp:19: In file included from ../boost/numeric/conversion/conversion_traits.hpp:13: In file included from ../boost/numeric/conversion/detail/conversion_traits.hpp:21: In file included from ../boost/numeric/conversion/detail/issubranged.hpp:17: In file included from ../boost/mpl/multiplies.hpp:17: In file included from ../boost/mpl/times.hpp:19: In file included from ../boost/mpl/aux/arithmetic_op.hpp:17: In file included from ../boost/mpl/integralc.hpp:32: ../boost/mpl/aux/integral_wrapper.hpp:73:31: error: integer value -1 is outside the valid range of values [0, 3] for this enumeration type [-Wenum-constexpr-conversion] typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUETYPE, (value - 1)) ) prior; ^ ../boost/mpl/aux/static_cast.hpp:24:47: note: expanded from macro 'BOOST_MPL_AUX_STATIC_CAST' # define BOOST_MPL_AUX_STATIC_CAST(T, expr) static_cast(expr) ^

The change https://github.com/boostorg/numeric_conversion/commit/50a1eae942effb0a9b90724323ef8f2a67e7984a is already present. Any ideas why it might not be effective in preventing the compile error in my environment? I am using somewhat uncommon standard C++ libraries (from VxWorks, modified Dinkum libraries), but it looks like most of the issue is inside Boost headers...

pdimov commented 1 year ago

Hard to say. I tried it on Compiler Explorer and it worked: https://godbolt.org/z/dhrscKoz1.