Opened 13 years ago

#3342 new Bugs

vector_c should use maximum integral constant type

Reported by: Maxim Yanchenko <Maxim.Yanchenko@…> Owned by: Aleksey Gurtovoy
Milestone: Boost 1.40.0 Component: mpl
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:

Description

It looks like currently long is built in, which leads to problems on 32 bit architectures with sizeofs int = long < int64_t.

How it's defined currently:

template<
      typename T, long C0 = LONG_MAX, long C1 = LONG_MAX, long C2 = LONG_MAX, ...
    >
struct vector_c;

I believe the maximum integral type (e.g. int64_t) should be used instead of long.

Example that shows the problem:

  const int64_t max_int         = integer_traits<int>::const_max;
  const int64_t max_int_plus_1  = max_int + 1;
  
  BOOST_MPL_ASSERT(( equal<           vector_c< int64_t, 1 >
                          , vector< integral_c< int64_t, 1 > >
                          > ));

  BOOST_MPL_ASSERT(( equal<           vector_c< int64_t, max_int >
                          , vector< integral_c< int64_t, max_int > >
                          > ));

  BOOST_MPL_ASSERT(( equal<           vector_c< int64_t, max_int_plus_1 >
                          , vector< integral_c< int64_t, max_int_plus_1 > >
                          > ));

The first assert passes, while the second and third fail with the following error messages (removed repetition of 2147483647l for readability):

test.h:149: error: ************mpl::equal<mpl::vector_c<int64_t, 2147483647l,
2147483647l, ...>, mpl::vector<mpl_::integral_c<int64_t, 2147483647>>,
is_same<true> >::************'
test.h:153: error: ************mpl::equal<mpl::vector_c<int64_t,
-0x00000000080000000l, 2147483647l, ...>, mpl::vector<mpl_::integral_c<int64_t,
2147483648ll>>, is_same<true> >::************'

Change History (0)

Note: See TracTickets for help on using tickets.