This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] libstdc++/21244


Gabriel Dos Reis wrote:

>| I went through the various occurrences and maybe the situation is not
>| really horrible: in most of the places, minimal arithmetic is carried
>| out. In other places the cast is either already present (e.g., case of
>| stl_deque.h) or the right type to use is explicit (e.g., case of
>| formatter.h). I wil prepare a complete patch and post it, ASAP.
>
>Wonderful!  Thanks,
>  
>
The below is the patch that I'm finishing testing (on x86-linux) and
would apply tomorrow both to mainline and 4.0.

Paolo.

///////////////////
2005-04-29  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.

	
diff -urN libstdc++-v3-orig/include/bits/cpp_type_traits.h libstdc++-v3/include/bits/cpp_type_traits.h
--- libstdc++-v3-orig/include/bits/cpp_type_traits.h	2005-02-01 14:30:29.000000000 +0100
+++ libstdc++-v3/include/bits/cpp_type_traits.h	2005-04-27 22:21:36.000000000 +0200
@@ -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;
     };
 
diff -urN libstdc++-v3-orig/include/bits/stl_algo.h libstdc++-v3/include/bits/stl_algo.h
--- libstdc++-v3-orig/include/bits/stl_algo.h	2005-04-18 18:04:04.000000000 +0200
+++ libstdc++-v3/include/bits/stl_algo.h	2005-04-28 00:00:24.000000000 +0200
@@ -2212,10 +2212,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);
@@ -2231,10 +2231,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
@@ -2481,7 +2481,7 @@
       typedef typename iterator_traits<_RandomAccessIterator>::value_type
 	_ValueType;
 
-      while (__last - __first > _S_threshold)
+      while (__last - __first > int(_S_threshold))
 	{
 	  if (__depth_limit == 0)
 	    {
@@ -2517,7 +2517,7 @@
       typedef typename iterator_traits<_RandomAccessIterator>::value_type
 	_ValueType;
 
-      while (__last - __first > _S_threshold)
+      while (__last - __first > int(_S_threshold))
 	{
 	  if (__depth_limit == 0)
 	    {
diff -urN libstdc++-v3-orig/include/bits/stl_bvector.h libstdc++-v3/include/bits/stl_bvector.h
--- libstdc++-v3-orig/include/bits/stl_bvector.h	2005-04-27 17:20:34.000000000 +0200
+++ libstdc++-v3/include/bits/stl_bvector.h	2005-04-27 23:27:41.000000000 +0200
@@ -64,7 +64,7 @@
 namespace _GLIBCXX_STD
 {
   typedef unsigned long _Bit_type;
-  enum _S_word_bit_enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
+  enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
 
   struct _Bit_reference
   {
@@ -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);
 	}
     }
diff -urN libstdc++-v3-orig/include/debug/formatter.h libstdc++-v3/include/debug/formatter.h
--- libstdc++-v3-orig/include/debug/formatter.h	2004-06-25 09:01:42.000000000 +0200
+++ libstdc++-v3/include/debug/formatter.h	2005-04-27 23:22:47.000000000 +0200
@@ -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;
diff -urN libstdc++-v3-orig/include/ext/mt_allocator.h libstdc++-v3/include/ext/mt_allocator.h
--- libstdc++-v3-orig/include/ext/mt_allocator.h	2005-01-26 17:34:56.000000000 +0100
+++ libstdc++-v3/include/ext/mt_allocator.h	2005-04-27 23:01:37.000000000 +0200
@@ -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);
diff -urN libstdc++-v3-orig/include/ext/pool_allocator.h libstdc++-v3/include/ext/pool_allocator.h
--- libstdc++-v3-orig/include/ext/pool_allocator.h	2004-11-24 05:11:13.000000000 +0100
+++ libstdc++-v3/include/ext/pool_allocator.h	2005-04-28 00:05:52.000000000 +0200
@@ -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
       {
diff -urN libstdc++-v3-orig/include/ext/rope libstdc++-v3/include/ext/rope
--- libstdc++-v3-orig/include/ext/rope	2005-01-16 20:16:26.000000000 +0100
+++ libstdc++-v3/include/ext/rope	2005-04-27 23:05:42.000000000 +0200
@@ -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.
diff -urN libstdc++-v3-orig/include/ext/ropeimpl.h libstdc++-v3/include/ext/ropeimpl.h
--- libstdc++-v3-orig/include/ext/ropeimpl.h	2004-09-02 20:22:20.000000000 +0200
+++ libstdc++-v3/include/ext/ropeimpl.h	2005-04-28 00:25:33.000000000 +0200
@@ -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]