[Boost-users] [integer_traits problem

6 views
Skip to first unread message

Robert Ramey

unread,
May 29, 2012, 7:26:12 PM5/29/12
to boost...@lists.boost.org
I'm having problems with integer traits when passed an __int64 type data
type under Visual C++.

I run the following test:

boost::mpl::print<
boost::mpl::integral_c<
boost::intmax_t,
boost::integer_traits<boost::intmax_t>::const_min
>
> x13;
boost::mpl::print<
boost::mpl::integral_c<
boost::intmax_t,
boost::integer_traits<boost::intmax_t>::const_max
>
> x8;


What I expect to get for const_min is:
...
1> T=boost::mpl::integral_c<boost::intmax_t,0x8000000000000000>
...


What I get is:

1>test_fixed_type.cpp
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral
constant converted to unsigned type
1> c:\projects\boost projects\safe_numerics\include\test_fixed_type.cpp(13)
: see reference to class template instantiation 'boost::mpl::print<T>' being
compiled
1> with
1> [
1> T=boost::mpl::integral_c<boost::intmax_t,0x800000000>
1> ]
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral
constant converted to unsigned type
1> c:\projects\boost projects\safe_numerics\include\test_fixed_type.cpp(20)
: see reference to class template instantiation 'boost::mpl::print<T>' being
compiled
1> with
1> [
1> T=boost::mpl::integral_c<boost::intmax_t,0x7fffffffffffffff>
1> ]

That is the value for const_min is not correct !!. Note I've tried various
different types such as using __int64 and also changed the rendering of he
real vale to _I64_MIN. None of this seems to fix things.

I've also tried making my own specialzation of integral_c for this type:

template<boost::intmax_t C >
struct integral_c<boost::intmax_t, C>
{
BOOST_STATIC_CONSTANT(boost::intmax_t, value = C);
typedef integral_c_tag tag;
typedef integral_c type;
typedef boost::intmax_t value_type;
operator boost::intmax_t() const { return this->value; }
};

Hmmm now I'm wondering about BOOST_STATIC_CONSTANT. and looking at the
documenation of BOOST_STATIC_CONSTANT shows it's not really expected to work
on anything wider than an int.

What should one do in a case like this?

Robert Ramey



_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Robert Ramey

unread,
May 29, 2012, 7:33:58 PM5/29/12
to boost...@lists.boost.org
I just changed the specialization above to:

template<boost::intmax_t C >
struct integral_c<boost::intmax_t, C>
{
//BOOST_STATIC_CONSTANT(boost::intmax_t, value = C);
static const boost::intmax_t value = C;
typedef integral_c_tag tag;
typedef integral_c type;
typedef boost::intmax_t value_type;
operator boost::intmax_t() const { return this->value; }
};

and it didn't make any difference so I"m really stumped

Robert Ramey

unread,
May 29, 2012, 7:57:17 PM5/29/12
to boost...@lists.boost.org
Robert Ramey wrote:

> I just changed the specialization above to:
>
> template<boost::intmax_t C >
> struct integral_c<boost::intmax_t, C>
> {
> //BOOST_STATIC_CONSTANT(boost::intmax_t, value = C);
> static const boost::intmax_t value = C;
> typedef integral_c_tag tag;
> typedef integral_c type;
> typedef boost::intmax_t value_type;
> operator boost::intmax_t() const { return this->value; }
> };
>
> and it didn't make any difference so I"m really stumped

I just ran the same test with GCC and it returns the result I expect.
So, I've got a problem with Visual C++ version 9.0. It looks
like the value const_min (_I64_min) is getting changed as it's passed as a
template parameter. If anyone has some experience with
this feel free to make a suggestion.
Reply all
Reply to author
Forward
0 new messages