Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78469 - in branches/release: boost boost/detail boost/integer libs/integer libs/integer/test
From: john_at_[hidden]
Date: 2012-05-14 11:58:00


Author: johnmaddock
Date: 2012-05-14 11:57:59 EDT (Mon, 14 May 2012)
New Revision: 78469
URL: http://svn.boost.org/trac/boost/changeset/78469

Log:
Merge minor integer fixes from Trunk.
Added:
   branches/release/libs/integer/test/fail_int_exact.cpp
      - copied unchanged from r78468, /trunk/libs/integer/test/fail_int_exact.cpp
   branches/release/libs/integer/test/fail_int_fast.cpp
      - copied unchanged from r78468, /trunk/libs/integer/test/fail_int_fast.cpp
   branches/release/libs/integer/test/fail_int_least.cpp
      - copied unchanged from r78468, /trunk/libs/integer/test/fail_int_least.cpp
   branches/release/libs/integer/test/fail_uint_exact.cpp
      - copied unchanged from r78468, /trunk/libs/integer/test/fail_uint_exact.cpp
   branches/release/libs/integer/test/fail_uint_fast.cpp
      - copied unchanged from r78468, /trunk/libs/integer/test/fail_uint_fast.cpp
   branches/release/libs/integer/test/fail_uint_least.cpp
      - copied unchanged from r78468, /trunk/libs/integer/test/fail_uint_least.cpp
Properties modified:
   branches/release/boost/cstdint.hpp (props changed)
   branches/release/boost/detail/fenv.hpp (props changed)
   branches/release/boost/integer/ (props changed)
   branches/release/boost/integer.hpp (contents, props changed)
   branches/release/boost/integer_fwd.hpp (props changed)
   branches/release/boost/integer_traits.hpp (props changed)
   branches/release/libs/integer/ (props changed)
Text files modified:
   branches/release/boost/integer.hpp | 34 +++++++++++++++++++---------------
   branches/release/libs/integer/test/Jamfile.v2 | 6 ++++++
   2 files changed, 25 insertions(+), 15 deletions(-)

Modified: branches/release/boost/integer.hpp
==============================================================================
--- branches/release/boost/integer.hpp (original)
+++ branches/release/boost/integer.hpp 2012-05-14 11:57:59 EDT (Mon, 14 May 2012)
@@ -20,6 +20,7 @@
 #include <boost/integer_traits.hpp> // for boost::::boost::integer_traits
 #include <boost/limits.hpp> // for ::std::numeric_limits
 #include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
+#include <boost/static_assert.hpp>
 
 //
 // We simply cannot include this header on gcc without getting copious warnings of the kind:
@@ -51,6 +52,7 @@
 
   // convert category to type
   template< int Category > struct int_least_helper {}; // default is empty
+ template< int Category > struct uint_least_helper {}; // default is empty
 
   // specializatons: 1=long, 2=int, 3=short, 4=signed char,
   // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
@@ -65,14 +67,14 @@
   template<> struct int_least_helper<4> { typedef short least; };
   template<> struct int_least_helper<5> { typedef signed char least; };
 #ifdef BOOST_HAS_LONG_LONG
- template<> struct int_least_helper<6> { typedef boost::ulong_long_type least; };
+ template<> struct uint_least_helper<1> { typedef boost::ulong_long_type least; };
 #elif defined(BOOST_HAS_MS_INT64)
- template<> struct int_least_helper<6> { typedef unsigned __int64 least; };
+ template<> struct uint_least_helper<1> { typedef unsigned __int64 least; };
 #endif
- template<> struct int_least_helper<7> { typedef unsigned long least; };
- template<> struct int_least_helper<8> { typedef unsigned int least; };
- template<> struct int_least_helper<9> { typedef unsigned short least; };
- template<> struct int_least_helper<10> { typedef unsigned char least; };
+ template<> struct uint_least_helper<2> { typedef unsigned long least; };
+ template<> struct uint_least_helper<3> { typedef unsigned int least; };
+ template<> struct uint_least_helper<4> { typedef unsigned short least; };
+ template<> struct uint_least_helper<5> { typedef unsigned char least; };
 
   template <int Bits>
   struct exact_signed_base_helper{};
@@ -111,10 +113,12 @@
   template< int Bits > // bits (including sign) required
   struct int_t : public detail::exact_signed_base_helper<Bits>
   {
+ BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::intmax_t) * CHAR_BIT),
+ "No suitable signed integer type with the requested number of bits is available.");
       typedef typename detail::int_least_helper
         <
 #ifdef BOOST_HAS_LONG_LONG
- (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
+ (Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
 #else
            1 +
 #endif
@@ -130,6 +134,8 @@
   template< int Bits > // bits required
   struct uint_t : public detail::exact_unsigned_base_helper<Bits>
   {
+ BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::uintmax_t) * CHAR_BIT),
+ "No suitable unsigned integer type with the requested number of bits is available.");
 #if (defined(__BORLANDC__) || defined(__CODEGEAR__)) && defined(BOOST_NO_INTEGRAL_INT64_T)
      // It's really not clear why this workaround should be needed... shrug I guess! JM
      BOOST_STATIC_CONSTANT(int, s =
@@ -140,11 +146,10 @@
           (Bits <= ::std::numeric_limits<unsigned char>::digits));
      typedef typename detail::int_least_helper< ::boost::uint_t<Bits>::s>::least least;
 #else
- typedef typename detail::int_least_helper
+ typedef typename detail::uint_least_helper
         <
- 5 +
 #ifdef BOOST_HAS_LONG_LONG
- (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
+ (Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
 #else
            1 +
 #endif
@@ -217,7 +222,7 @@
      // It's really not clear why this workaround should be needed... shrug I guess! JM
 #if defined(BOOST_NO_INTEGRAL_INT64_T)
       BOOST_STATIC_CONSTANT(unsigned, which =
- 6 +
+ 1 +
           (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
           (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
           (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
@@ -225,18 +230,17 @@
       typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
 #else // BOOST_NO_INTEGRAL_INT64_T
       BOOST_STATIC_CONSTANT(unsigned, which =
- 5 +
+ 1 +
           (MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
           (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
           (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
           (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
           (MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
- typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
+ typedef typename detail::uint_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
 #endif // BOOST_NO_INTEGRAL_INT64_T
 #else
- typedef typename detail::int_least_helper
+ typedef typename detail::uint_least_helper
         <
- 5 +
 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
           (MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
 #else

Modified: branches/release/libs/integer/test/Jamfile.v2
==============================================================================
--- branches/release/libs/integer/test/Jamfile.v2 (original)
+++ branches/release/libs/integer/test/Jamfile.v2 2012-05-14 11:57:59 EDT (Mon, 14 May 2012)
@@ -22,4 +22,10 @@
         [ compile static_log2_include_test.cpp ]
         [ compile static_min_max_include_test.cpp ]
         [ compile integer_fwd_include_test.cpp ]
+ [ compile-fail fail_int_exact.cpp ]
+ [ compile-fail fail_int_fast.cpp ]
+ [ compile-fail fail_int_least.cpp ]
+ [ compile-fail fail_uint_exact.cpp ]
+ [ compile-fail fail_uint_fast.cpp ]
+ [ compile-fail fail_uint_least.cpp ]
     ;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk