This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[RFA]: Fix libstdc++ to build for HC11/HC12 (3_3 branch)


Hi!

The libstdc++ uses std::min() and std::max() templates at various places.  When one of the
argument is an expression it can be widden to the 'int' type, thus resulting in

  size_type min(int, size_type)
  ptrdiff_t max(int, ptrdiff_t)

but the min/max templates do not match those signatures
(sizeof(size_type) == 16, sizeof(ptrdiff_t) == 16, sizeof(int) == 32).

This patch adds the necessary casts to solve this problem.  With it, it is now possible
to build completely the libstdc++ on HC11/HC12.

Verified on m6811-elf and i686-linux (make bootstrap).

Can you approve this patch for 3_3 branch?

Thanks,
	Stephane

2003-03-16 Stephane Carrez <stcarrez at nerim dot fr>

	* include/bits/basic_string.tcc (basic_string::append): Add size_type
	cast.
	(basic_string::rfind): Likewise.
	(basic_string::compare): Likewise.
	* src/strstream.cc (strstreambuf::overflow): Add ptrdiff_t cast.
Index: include/bits/basic_string.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_string.tcc,v
retrieving revision 1.29.2.1
diff -u -p -r1.29.2.1 basic_string.tcc
--- include/bits/basic_string.tcc	28 Feb 2003 02:28:12 -0000	1.29.2.1
+++ include/bits/basic_string.tcc	16 Mar 2003 21:40:33 -0000
@@ -578,7 +578,8 @@ namespace std
       // Iff appending itself, string needs to pre-reserve the
       // correct size so that _M_mutate does not clobber the
       // iterators formed here.
-      size_type __len = std::min(__str.size() - __pos, __n) + this->size();
+      size_type __len = std::min((size_type) (__str.size() - __pos),
+                                 __n) + this->size();
       if (__len > this->capacity())
 	this->reserve(__len);
       return _M_replace_safe(_M_iend(), _M_iend(), __str._M_check(__pos),
@@ -709,7 +710,7 @@ namespace std
       size_type __size = this->size();
       if (__n <= __size)
 	{
-	  __pos = std::min(__size - __n, __pos);
+	  __pos = std::min((size_type) (__size - __n), __pos);
 	  const _CharT* __data = _M_data();
 	  do 
 	    {
@@ -848,7 +849,7 @@ namespace std
       if (__pos > __size)
 	__throw_out_of_range("basic_string::compare");
       
-      size_type __rsize= std::min(__size - __pos, __n);
+      size_type __rsize= std::min((size_type) (__size - __pos), __n);
       size_type __len = std::min(__rsize, __osize);
       int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
       if (!__r)
@@ -867,8 +868,8 @@ namespace std
       if (__pos1 > __size || __pos2 > __osize)
 	__throw_out_of_range("basic_string::compare");
       
-      size_type __rsize = std::min(__size - __pos1, __n1);
-      size_type __rosize = std::min(__osize - __pos2, __n2);
+      size_type __rsize = std::min((size_type) (__size - __pos1), __n1);
+      size_type __rosize = std::min((size_type) (__osize - __pos2), __n2);
       size_type __len = std::min(__rsize, __rosize);
       int __r = traits_type::compare(_M_data() + __pos1, 
 				     __str.data() + __pos2, __len);
@@ -903,7 +904,7 @@ namespace std
 	__throw_out_of_range("basic_string::compare");
       
       size_type __osize = traits_type::length(__s);
-      size_type __rsize = std::min(__size - __pos, __n1);
+      size_type __rsize = std::min((size_type) (__size - __pos), __n1);
       size_type __len = std::min(__rsize, __osize);
       int __r = traits_type::compare(_M_data() + __pos, __s, __len);
       if (!__r)
@@ -922,7 +923,7 @@ namespace std
 	__throw_out_of_range("basic_string::compare");
       
       size_type __osize = std::min(traits_type::length(__s), __n2);
-      size_type __rsize = std::min(__size - __pos, __n1);
+      size_type __rsize = std::min((size_type) (__size - __pos), __n1);
       size_type __len = std::min(__rsize, __osize);
       int __r = traits_type::compare(_M_data() + __pos, __s, __len);
       if (!__r)
Index: src/strstream.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/strstream.cc,v
retrieving revision 1.14
diff -u -p -r1.14 strstream.cc
--- src/strstream.cc	11 Sep 2002 03:36:45 -0000	1.14
+++ src/strstream.cc	16 Mar 2003 21:40:34 -0000
@@ -148,7 +148,7 @@ namespace std
     if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant) 
       {
 	ptrdiff_t old_size = epptr() - pbase();
-	ptrdiff_t new_size = max(2 * old_size, ptrdiff_t(1));
+	ptrdiff_t new_size = max((ptrdiff_t) (2 * old_size), ptrdiff_t(1));
 	
 	char* buf = _M_alloc(new_size);
 	if (buf) 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]