Opened 12 years ago

Last modified 12 years ago

#5268 new Bugs

mpl::int_<INT_MIN> fails to compile under g++-4.6 although g++-4.5 works.

Reported by: Stirling Westrup <swestrup@…> Owned by: Aleksey Gurtovoy
Milestone: To Be Determined Component: mpl
Version: Boost 1.46.0 Severity: Problem
Keywords: int_ INT_MIN Cc:

Description

Under Debian Sid with a 2.6.36 AMD_64 kernel, and g++-4.6, the following code:

#include <climits>
#include <boost/mpl/int.hpp>

boost::mpl::int_<INT_MIN> foo;

Produces the errors:

/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp: In instantiation of ‘mpl_::int_<-0x00000000080000000>’:
test_test.cpp:8:27:   instantiated from here
/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error: ‘2147483647’ is not a valid template argument for type ‘int’ because it is a non-constant expression
/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error: overflow in constant expression [-fpermissive]

Change History (1)

comment:1 by Stirling Westrup <swestrup@…>, 12 years ago

I also reported this bug to GCC, and this is what they had to say about it:

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#699 added integer overflow ("a result that is not mathematically defined or not in the range of representable values for its type") to the list of things that cause an expression to not be a constant expression

The non-type template argument needs to be an integral constant-expression, but it's not a constant expression due to the overflow, so the code is invalid.

Whether it should be accepted with -fpermissive is a separate matter, as is the quality of diagnostic.

So, it appears to be a genuine bug in mpl, which will need to be fixed.

Note: See TracTickets for help on using tickets.