$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r48729 - trunk/libs/dynamic_bitset
From: gennaro.prota_at_[hidden]
Date: 2008-09-11 05:35:50
Author: gennaro_prota
Date: 2008-09-11 05:35:49 EDT (Thu, 11 Sep 2008)
New Revision: 48729
URL: http://svn.boost.org/trac/boost/changeset/48729
Log:
dynamic_bitset: in dyn_bitset_unit_tests1.cpp, replaced very ill-thought assert() with more sensible code to check for "negative sizes"
Text files modified: 
   trunk/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp |    19 ++++++++++++++++---                     
   1 files changed, 16 insertions(+), 3 deletions(-)
Modified: trunk/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp
==============================================================================
--- trunk/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp	(original)
+++ trunk/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp	2008-09-11 05:35:49 EDT (Thu, 11 Sep 2008)
@@ -81,9 +81,22 @@
           // can match ctor from ulong or templated one
           Tests::from_unsigned_long(sizes[s], numbers[n]);
 
-          // can match templated ctor only (so we test dispatching)
-          assert( sizes[s] < (std::numeric_limits<char>::max)() );
-          Tests::from_unsigned_long(static_cast<T>(sizes[s]), numbers[n]);
+          typedef std::size_t compare_type;
+          const compare_type sz = sizes[s];
+          // this condition is to be sure that size is representable in T, so
+          // that for signed T's we avoid implementation-defined behavior [if ma
+          // is larger than what std::size_t can hold then this is ok for our
+          // purposes: our sizes are anyhow < max(size_t)], which in turn could
+          // make the first argument of from_unsigned_long() a small negative,
+          // later converted to a very large unsigned. Example: signed 8-bit
+          // char (CHAR_MAX=127), bits_per_block=64, sz = 192 > 127.
+          const bool fits =
+              sz <= static_cast<compare_type>(ma);
+
+          if (fits) {
+            // can match templated ctor only (so we test dispatching)
+            Tests::from_unsigned_long(static_cast<T>(sizes[s]), numbers[n]);
+          }
 
       }
     }