pr21244.patch   [plain text]


2005-04-28  Paolo Carlini  <pcarlini@suse.de>
	    Gabriel Dos Reis  <gdr@integrable-solutions.net>

	PR libstdc++/21244 (cont)
	* include/bits/cpp_type_traits.h (struct __traitor): Convert
	to bool the values.
	* include/bits/stl_algo.h: Convert _S_threshold to int.
	* include/bits/stl_bvector.h: Revert previous change, convert
	_S_word_bit to int.
	* include/debug/formatter.h: Convert __max_parameters to
	size_t.
	* include/ext/mt_allocator.h: Likewise for _S_chunk_size.
	* include/ext/pool_allocator.h: Likewise for _S_max_bytes and
	_S_align.
	* include/ext/rope: Likewise for _S_alloc_granularity; convert
	_S_max_rope_depth to int.
	* include/ext/ropeimpl.h: Convert _S_path_cache_len to int;
	_S_max_rope_depth to int; _S_copy_max to size_t.

2005-07-11  Paolo Carlini  <pcarlini@suse.de>
	    
	PR libstdc++/21244 (cont^2)
	* include/ext/bitmap_allocator.h: Convert everywhere
	bits_per_block to size_t.

Index: libstdc++-v3/include/ext/pool_allocator.h
===================================================================
--- libstdc++-v3/include/ext/pool_allocator.h	(revision 98916)
+++ libstdc++-v3/include/ext/pool_allocator.h	(revision 98917)
@@ -80,7 +80,7 @@
 
       enum { _S_align = 8 };
       enum { _S_max_bytes = 128 };
-      enum { _S_free_list_size = _S_max_bytes / _S_align };
+      enum { _S_free_list_size = (size_t)_S_max_bytes / (size_t)_S_align };
       
       union _Obj
       {
Index: libstdc++-v3/include/ext/rope
===================================================================
--- libstdc++-v3/include/ext/rope	(revision 98916)
+++ libstdc++-v3/include/ext/rope	(revision 98917)
@@ -676,8 +676,8 @@
 	return __size_with_eos;
 #else
 	// Allow slop for in-place expansion.
-	return ((__size_with_eos + _S_alloc_granularity - 1)
-		&~ (_S_alloc_granularity - 1));
+	return ((__size_with_eos + size_t(_S_alloc_granularity) - 1)
+		&~ (size_t(_S_alloc_granularity) - 1));
 #endif
       }
       __GC_CONST _CharT* _M_data; /* Not necessarily 0 terminated. */
@@ -1998,7 +1998,7 @@
       size_type
       max_size() const
       {
-	return _S_min_len[_Rope_constants::_S_max_rope_depth - 1] - 1;
+	return _S_min_len[int(_Rope_constants::_S_max_rope_depth) - 1] - 1;
 	//  Guarantees that the result can be sufficirntly
 	//  balanced.  Longer ropes will probably still work,
 	//  but it's harder to make guarantees.
Index: libstdc++-v3/include/ext/mt_allocator.h
===================================================================
--- libstdc++-v3/include/ext/mt_allocator.h	(revision 98916)
+++ libstdc++-v3/include/ext/mt_allocator.h	(revision 98917)
@@ -503,7 +503,7 @@
 	static _Tune _S_tune(__align, sizeof(_Tp) * 64,
 			     sizeof(_Tp) * 2 >= __align ? sizeof(_Tp) * 2
 			                                : __align,
-			     sizeof(_Tp) * _Tune::_S_chunk_size,
+			     sizeof(_Tp) * size_t(_Tune::_S_chunk_size),
 			     _Tune::_S_max_threads,
 			     _Tune::_S_freelist_headroom,
 			     getenv("GLIBCXX_FORCE_NEW") ? true : false);
@@ -549,7 +549,7 @@
 	static _Tune _S_tune(__align, sizeof(_Tp) * 64,
 			     sizeof(_Tp) * 2 >= __align ? sizeof(_Tp) * 2
                                                         : __align,
-			     sizeof(_Tp) * _Tune::_S_chunk_size,
+			     sizeof(_Tp) * size_t(_Tune::_S_chunk_size),
 			     _Tune::_S_max_threads,
 			     _Tune::_S_freelist_headroom,
 			     getenv("GLIBCXX_FORCE_NEW") ? true : false);
Index: libstdc++-v3/include/ext/ropeimpl.h
===================================================================
--- libstdc++-v3/include/ext/ropeimpl.h	(revision 98916)
+++ libstdc++-v3/include/ext/ropeimpl.h	(revision 98917)
@@ -116,7 +116,7 @@
     _Rope_iterator_base<_CharT, _Alloc>::
     _S_setcache(_Rope_iterator_base<_CharT, _Alloc>& __x)
     {
-      const _RopeRep* __path[_Rope_constants::_S_max_rope_depth + 1];
+      const _RopeRep* __path[int(_Rope_constants::_S_max_rope_depth) + 1];
       const _RopeRep* __curr_rope;
       int __curr_depth = -1;  /* index into path    */
       size_t __curr_start_pos = 0;
@@ -175,7 +175,7 @@
       // Copy last section of path into _M_path_end.
       {
 	int __i = -1;
-	int __j = __curr_depth + 1 - _S_path_cache_len;
+	int __j = __curr_depth + 1 - int(_S_path_cache_len);
 
 	if (__j < 0) __j = 0;
 	while (__j <= __curr_depth)
@@ -236,10 +236,10 @@
       while (_Rope_constants::_S_concat == __current_node->_M_tag)
 	{
 	  ++__current_index;
-	  if (_S_path_cache_len == __current_index)
+	  if (int(_S_path_cache_len) == __current_index)
 	    {
 	      int __i;
-	      for (__i = 0; __i < _S_path_cache_len-1; __i++)
+	      for (__i = 0; __i < int(_S_path_cache_len) - 1; __i++)
 		__x._M_path_end[__i] = __x._M_path_end[__i+1];
 	      --__current_index;
 	    }
@@ -500,8 +500,9 @@
 							      get_allocator());
       size_t __depth = __result->_M_depth;
       
-      if (__depth > 20 && (__result->_M_size < 1000
-			   || __depth > _Rope_constants::_S_max_rope_depth))
+      if (__depth > 20
+	  && (__result->_M_size < 1000
+	      || __depth > size_t(_Rope_constants::_S_max_rope_depth)))
 	{
 	  _RopeRep* __balanced;
 
@@ -540,7 +541,7 @@
 	return __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen,
 						__r->get_allocator());
       if (_Rope_constants::_S_leaf == __r->_M_tag
-	  && __r->_M_size + __slen <= _S_copy_max)
+	  && __r->_M_size + __slen <= size_t(_S_copy_max))
 	{
 	  __result = _S_leaf_concat_char_iter((_RopeLeaf*)__r, __s, __slen);
 	  return __result;
@@ -551,7 +552,7 @@
 	{
 	  _RopeLeaf* __right =
 	    (_RopeLeaf* )(((_RopeConcatenation* )__r)->_M_right);
-	  if (__right->_M_size + __slen <= _S_copy_max)
+	  if (__right->_M_size + __slen <= size_t(_S_copy_max))
 	    {
 	      _RopeRep* __left = ((_RopeConcatenation*)__r)->_M_left;
 	      _RopeRep* __nright =
@@ -603,7 +604,7 @@
 	  __r->_M_ref_count = 2;      // One more than before
 	  return __r;
 	}
-      if (__orig_size + __slen <= _S_copy_max
+      if (__orig_size + __slen <= size_t(_S_copy_max)
 	  && _Rope_constants::_S_leaf == __r->_M_tag)
 	{
 	  __result = _S_destr_leaf_concat_char_iter((_RopeLeaf*)__r, __s, 
@@ -615,7 +616,7 @@
 	  _RopeLeaf* __right = (_RopeLeaf*)(((_RopeConcatenation*)
 					     __r)->_M_right);
 	  if (_Rope_constants::_S_leaf == __right->_M_tag
-	      && __right->_M_size + __slen <= _S_copy_max)
+	      && __right->_M_size + __slen <= size_t(_S_copy_max))
 	    {
 	      _RopeRep* __new_right =
 		_S_destr_leaf_concat_char_iter(__right, __s, __slen);
@@ -668,7 +669,7 @@
 	{
 	  if (_Rope_constants::_S_leaf == __left->_M_tag)
 	    {
-	      if (__right->_M_size + __left->_M_size <= _S_copy_max)
+	      if (__right->_M_size + __left->_M_size <= size_t(_S_copy_max))
 		return _S_leaf_concat_char_iter((_RopeLeaf*)__left,
 						((_RopeLeaf*)__right)->_M_data,
 						__right->_M_size);
@@ -679,7 +680,8 @@
 	    {
 	      _RopeLeaf* __leftright =
 		(_RopeLeaf*)(((_RopeConcatenation*)__left)->_M_right);
-	      if (__leftright->_M_size + __right->_M_size <= _S_copy_max)
+	      if (__leftright->_M_size
+		  + __right->_M_size <= size_t(_S_copy_max))
 		{
 		  _RopeRep* __leftleft = ((_RopeConcatenation*)__left)->_M_left;
 		  _RopeRep* __rest = _S_leaf_concat_char_iter(__leftright,
@@ -1184,7 +1186,7 @@
   template <class _CharT, class _Alloc>
     const unsigned long
     rope<_CharT, _Alloc>::
-    _S_min_len[_Rope_constants::_S_max_rope_depth + 1] = {
+    _S_min_len[int(_Rope_constants::_S_max_rope_depth) + 1] = {
       /* 0 */1, /* 1 */2, /* 2 */3, /* 3 */5, /* 4 */8, /* 5 */13, /* 6 */21,
       /* 7 */34, /* 8 */55, /* 9 */89, /* 10 */144, /* 11 */233, /* 12 */377,
       /* 13 */610, /* 14 */987, /* 15 */1597, /* 16 */2584, /* 17 */4181,
@@ -1203,7 +1205,7 @@
     rope<_CharT, _Alloc>::
     _S_balance(_RopeRep* __r)
     {
-      _RopeRep* __forest[_Rope_constants::_S_max_rope_depth + 1];
+      _RopeRep* __forest[int(_Rope_constants::_S_max_rope_depth) + 1];
       _RopeRep* __result = 0;
       int __i;
       // Invariant:
@@ -1212,12 +1214,12 @@
       // __forest[__i]._M_depth = __i
       // References from forest are included in refcount.
       
-      for (__i = 0; __i <= _Rope_constants::_S_max_rope_depth; ++__i)
+      for (__i = 0; __i <= int(_Rope_constants::_S_max_rope_depth); ++__i)
 	__forest[__i] = 0;
       try
 	{
 	  _S_add_to_forest(__r, __forest);
-	  for (__i = 0; __i <= _Rope_constants::_S_max_rope_depth; ++__i)
+	  for (__i = 0; __i <= int(_Rope_constants::_S_max_rope_depth); ++__i)
 	    if (0 != __forest[__i])
 	      {
 #ifndef __GC
@@ -1232,12 +1234,12 @@
 	}
       catch(...)
 	{
-	  for(__i = 0; __i <= _Rope_constants::_S_max_rope_depth; __i++)
+	  for(__i = 0; __i <= int(_Rope_constants::_S_max_rope_depth); __i++)
 	    _S_unref(__forest[__i]);
 	  __throw_exception_again;
 	}
       
-      if (__result->_M_depth > _Rope_constants::_S_max_rope_depth)
+      if (__result->_M_depth > int(_Rope_constants::_S_max_rope_depth))
 	__throw_length_error(__N("rope::_S_balance"));
       return(__result);
     }
@@ -1305,7 +1307,7 @@
 	      __forest[__i]->_M_unref_nonnil();
 	      __forest[__i] = 0;
 	    }
-	  if (__i == _Rope_constants::_S_max_rope_depth
+	  if (__i == int(_Rope_constants::_S_max_rope_depth)
 	      || __insertee->_M_size < _S_min_len[__i+1])
 	    {
 	      __forest[__i] = __insertee;
Index: libstdc++-v3/include/bits/stl_algo.h
===================================================================
--- libstdc++-v3/include/bits/stl_algo.h	(revision 98916)
+++ libstdc++-v3/include/bits/stl_algo.h	(revision 98917)
@@ -2211,10 +2211,10 @@
     __final_insertion_sort(_RandomAccessIterator __first,
 			   _RandomAccessIterator __last)
     {
-      if (__last - __first > _S_threshold)
+      if (__last - __first > int(_S_threshold))
 	{
-	  std::__insertion_sort(__first, __first + _S_threshold);
-	  std::__unguarded_insertion_sort(__first + _S_threshold, __last);
+	  std::__insertion_sort(__first, __first + int(_S_threshold));
+	  std::__unguarded_insertion_sort(__first + int(_S_threshold), __last);
 	}
       else
 	std::__insertion_sort(__first, __last);
@@ -2230,10 +2230,10 @@
     __final_insertion_sort(_RandomAccessIterator __first,
 			   _RandomAccessIterator __last, _Compare __comp)
     {
-      if (__last - __first > _S_threshold)
+      if (__last - __first > int(_S_threshold))
 	{
-	  std::__insertion_sort(__first, __first + _S_threshold, __comp);
-	  std::__unguarded_insertion_sort(__first + _S_threshold, __last,
+	  std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
+	  std::__unguarded_insertion_sort(__first + int(_S_threshold), __last,
 					  __comp);
 	}
       else
@@ -2480,7 +2480,7 @@
       typedef typename iterator_traits<_RandomAccessIterator>::value_type
 	_ValueType;
 
-      while (__last - __first > _S_threshold)
+      while (__last - __first > int(_S_threshold))
 	{
 	  if (__depth_limit == 0)
 	    {
@@ -2516,7 +2516,7 @@
       typedef typename iterator_traits<_RandomAccessIterator>::value_type
 	_ValueType;
 
-      while (__last - __first > _S_threshold)
+      while (__last - __first > int(_S_threshold))
 	{
 	  if (__depth_limit == 0)
 	    {
Index: libstdc++-v3/include/bits/stl_bvector.h
===================================================================
--- libstdc++-v3/include/bits/stl_bvector.h	(revision 98916)
+++ libstdc++-v3/include/bits/stl_bvector.h	(revision 98917)
@@ -117,7 +117,7 @@
     void
     _M_bump_up()
     {
-      if (_M_offset++ == _S_word_bit - 1)
+      if (_M_offset++ == int(_S_word_bit) - 1)
 	{
 	  _M_offset = 0;
 	  ++_M_p;
@@ -129,7 +129,7 @@
     {
       if (_M_offset-- == 0)
 	{
-	  _M_offset = _S_word_bit - 1;
+	  _M_offset = int(_S_word_bit) - 1;
 	  --_M_p;
 	}
     }
@@ -138,11 +138,11 @@
     _M_incr(ptrdiff_t __i)
     {
       difference_type __n = __i + _M_offset;
-      _M_p += __n / _S_word_bit;
-      __n = __n % _S_word_bit;
+      _M_p += __n / int(_S_word_bit);
+      __n = __n % int(_S_word_bit);
       if (__n < 0)
 	{
-	  _M_offset = static_cast<unsigned int>(__n + _S_word_bit);
+	  _M_offset = static_cast<unsigned int>(__n + int(_S_word_bit));
 	  --_M_p;
 	}
       else
@@ -180,7 +180,8 @@
   inline ptrdiff_t
   operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
   {
-    return _S_word_bit * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
+    return (int(_S_word_bit) * (__x._M_p - __y._M_p)
+	    + __x._M_offset - __y._M_offset);
   }
 
   struct _Bit_iterator : public _Bit_iterator_base
@@ -384,7 +385,8 @@
 
       _Bit_type*
       _M_allocate(size_t __n)
-      { return _M_impl.allocate((__n + _S_word_bit - 1) / _S_word_bit); }
+      { return _M_impl.allocate((__n + int(_S_word_bit) - 1)
+				/ int(_S_word_bit)); }
 
       void
       _M_deallocate()
@@ -452,8 +454,8 @@
     {
       _Bit_type* __q = this->_M_allocate(__n);
       this->_M_impl._M_end_of_storage = (__q
-					 + ((__n + _S_word_bit - 1)
-					    / _S_word_bit));
+					 + ((__n + int(_S_word_bit) - 1)
+					    / int(_S_word_bit)));
       this->_M_impl._M_start = iterator(__q, 0);
       this->_M_impl._M_finish = this->_M_impl._M_start + difference_type(__n);
     }
@@ -477,8 +479,9 @@
 	  *__i++ = __x;
 	  this->_M_impl._M_finish = std::copy(__position, end(), __i);
 	  this->_M_deallocate();
-	  this->_M_impl._M_end_of_storage = (__q + ((__len + _S_word_bit - 1)
-						    / _S_word_bit));
+	  this->_M_impl._M_end_of_storage = (__q + ((__len
+						     + int(_S_word_bit) - 1)
+						    / int(_S_word_bit)));
 	  this->_M_impl._M_start = iterator(__q, 0);
 	}
     }
@@ -543,8 +546,9 @@
 		this->_M_impl._M_finish = std::copy(__position, end(), __i);
 		this->_M_deallocate();
 		this->_M_impl._M_end_of_storage = (__q
-						   + ((__len + _S_word_bit - 1)
-						      / _S_word_bit));
+						   + ((__len
+						       + int(_S_word_bit) - 1)
+						      / int(_S_word_bit)));
 		this->_M_impl._M_start = iterator(__q, 0);
 	      }
 	  }
@@ -782,8 +786,8 @@
 					      iterator(__q, 0));
 	  this->_M_deallocate();
 	  this->_M_impl._M_start = iterator(__q, 0);
-	  this->_M_impl._M_end_of_storage = (__q + (__n + _S_word_bit - 1)
-					     / _S_word_bit);
+	  this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1)
+					     / int(_S_word_bit));
 	}
     }
 
@@ -888,8 +892,9 @@
 	  this->_M_impl._M_finish = std::copy(__position, end(),
 					      __i + difference_type(__n));
 	  this->_M_deallocate();
-	  this->_M_impl._M_end_of_storage = (__q + ((__len + _S_word_bit - 1)
-						    / _S_word_bit));
+	  this->_M_impl._M_end_of_storage = (__q + ((__len
+						     + int(_S_word_bit) - 1)
+						    / int(_S_word_bit)));
 	  this->_M_impl._M_start = iterator(__q, 0);
 	}
     }
Index: libstdc++-v3/include/bits/cpp_type_traits.h
===================================================================
--- libstdc++-v3/include/bits/cpp_type_traits.h	(revision 98916)
+++ libstdc++-v3/include/bits/cpp_type_traits.h	(revision 98917)
@@ -103,10 +103,12 @@
     struct __truth_type<true>
     { typedef __true_type __type; };
 
+  // N.B. The conversions to bool are needed due to the issue
+  // explained in c++/19404.
   template<class _Sp, class _Tp>
     struct __traitor
     {
-      enum { __value = _Sp::__value || _Tp::__value };
+      enum { __value = bool(_Sp::__value) || bool(_Tp::__value) };
       typedef typename __truth_type<__value>::__type __type;
     };
 
Index: libstdc++-v3/include/debug/formatter.h
===================================================================
--- libstdc++-v3/include/debug/formatter.h	(revision 98916)
+++ libstdc++-v3/include/debug/formatter.h	(revision 98917)
@@ -1,7 +1,6 @@
 // Debug-mode error formatting implementation -*- C++ -*-
 
-// Copyright (C) 2003, 2004
-// Free Software Foundation, Inc.
+// Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -310,7 +309,7 @@
       const _Error_formatter&
       _M_iterator(const _Iterator& __it, const char* __name = 0)  const
       {
-	if (_M_num_parameters < __max_parameters)
+	if (_M_num_parameters < size_t(__max_parameters))
 	  _M_parameters[_M_num_parameters++] = _Parameter(__it, __name,
 							  _Is_iterator());
 	return *this;
@@ -319,7 +318,7 @@
     const _Error_formatter&
     _M_integer(long __value, const char* __name = 0) const
     {
-      if (_M_num_parameters < __max_parameters)
+      if (_M_num_parameters < size_t(__max_parameters))
 	_M_parameters[_M_num_parameters++] = _Parameter(__value, __name);
       return *this;
     }
@@ -327,7 +326,7 @@
     const _Error_formatter&
     _M_string(const char* __value, const char* __name = 0) const
     {
-      if (_M_num_parameters < __max_parameters)
+      if (_M_num_parameters < size_t(__max_parameters))
 	_M_parameters[_M_num_parameters++] = _Parameter(__value, __name);
       return *this;
     }
@@ -336,7 +335,7 @@
       const _Error_formatter&
       _M_sequence(const _Sequence& __seq, const char* __name = 0) const
       {
-	if (_M_num_parameters < __max_parameters)
+	if (_M_num_parameters < size_t(__max_parameters))
 	  _M_parameters[_M_num_parameters++] = _Parameter(__seq, __name,
 							  _Is_sequence());
 	return *this;
Index: libstdc++-v3/include/ext/bitmap_allocator.h
===================================================================
--- libstdc++-v3/include/ext/bitmap_allocator.h	(revision 101873)
+++ libstdc++-v3/include/ext/bitmap_allocator.h	(revision 101874)
@@ -401,8 +401,8 @@
 
     enum 
       { 
-	bits_per_byte = 8, 
-	bits_per_block = sizeof(size_t) * bits_per_byte 
+	bits_per_byte = 8,
+	bits_per_block = sizeof(size_t) * size_t(bits_per_byte) 
       };
 
     template<typename _ForwardIterator, typename _Tp, typename _Compare>
@@ -459,7 +459,7 @@
     template<typename _AddrPair>
       inline size_t
       __num_bitmaps(_AddrPair __ap)
-      { return __num_blocks(__ap) / bits_per_block; }
+      { return __num_blocks(__ap) / size_t(bits_per_block); }
 
     // _Tp should be a pointer type.
     template<typename _Tp>
@@ -570,7 +570,7 @@
 
 	_Counter_type
 	_M_offset() const throw()
-	{ return _M_data_offset * bits_per_block; }
+	{ return _M_data_offset * size_t(bits_per_block); }
       };
 
 
@@ -620,7 +620,7 @@
 	  _M_last_bmap_in_block = _M_curr_bmap
 	    - ((_M_vbp[_M_curr_index].second 
 		- _M_vbp[_M_curr_index].first + 1) 
-	       / bits_per_block - 1);
+	       / size_t(bits_per_block) - 1);
 	}
     
 	// Dangerous Function! Use with extreme care. Pass to this
@@ -660,7 +660,7 @@
 	_Index_type
 	_M_offset() const throw()
 	{
-	  return bits_per_block
+	  return size_t(bits_per_block)
 	    * ((reinterpret_cast<size_t*>(this->_M_base()) 
 		- _M_curr_bmap) - 1);
 	}
@@ -938,7 +938,8 @@
 	_S_check_for_free_blocks();
 #endif
 
-	const size_t __num_bitmaps = _S_block_size / balloc::bits_per_block;
+	const size_t __num_bitmaps = (_S_block_size
+				      / size_t(balloc::bits_per_block));
 	const size_t __size_to_allocate = sizeof(size_t) 
 	  + _S_block_size * sizeof(_Alloc_block) 
 	  + __num_bitmaps * sizeof(size_t);
@@ -1136,11 +1137,12 @@
 	  }
 
 	// Get the position of the iterator that has been found.
-	const size_t __rotate = __displacement % balloc::bits_per_block;
+	const size_t __rotate = (__displacement
+				 % size_t(balloc::bits_per_block));
 	size_t* __bitmapC = 
 	  reinterpret_cast<size_t*>
 	  (_S_mem_blocks[__diff].first) - 1;
-	__bitmapC -= (__displacement / balloc::bits_per_block);
+	__bitmapC -= (__displacement / size_t(balloc::bits_per_block));
       
 	balloc::__bit_free(__bitmapC, __rotate);
 	size_t* __puse_count = reinterpret_cast<size_t*>
@@ -1267,7 +1269,7 @@
 
   template<typename _Tp>
     size_t bitmap_allocator<_Tp>::_S_block_size = 
-    2 * balloc::bits_per_block;
+    2 * size_t(balloc::bits_per_block);
 
   template<typename _Tp>
     typename __gnu_cxx::bitmap_allocator<_Tp>::_BPVector::size_type