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]

New max() problem with integer promotion and narrow size_t


New problem that affects this target with narrower size_t than int.
Integer promotion causes max() to get two different data types, so it
can't match.  BTW, I'm not sure it wouldn't be appropriate to cast the
second argument to __size_type as well, since it is my understanding
that there's no guarantee that the string and the buf size_types are
going to be the same.  Anyway, I'm going ahead and checking this in as
obvious.

Index: libstdc++-v3/ChangeLog
from  Alexandre Oliva  <aoliva at redhat dot com>

	* include/bits/sstream.tcc (overflow): Make sure operands of min
	and max have the same type.

Index: libstdc++-v3/include/bits/sstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/sstream.tcc,v
retrieving revision 1.18
diff -u -p -r1.18 sstream.tcc
--- libstdc++-v3/include/bits/sstream.tcc 31 Mar 2003 18:24:13 -0000 1.18
+++ libstdc++-v3/include/bits/sstream.tcc 8 Apr 2003 11:47:14 -0000
@@ -1,6 +1,6 @@
 // String based streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2001, 2002
+// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -90,7 +90,7 @@ namespace std
       // In virtue of DR 169 (TC) we are allowed to grow more than
       // one char the first time and also...
       __size_type __len =
-	std::max(_M_string.capacity() + 1, this->_M_buf_size_opt);
+	std::max(__size_type(_M_string.capacity() + 1), this->_M_buf_size_opt);
 
       bool __testwrite = this->_M_out_cur < this->_M_out_end;
       if (__builtin_expect(!__testwrite && __len > _M_string.max_size(), false))
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist                Professional serial bug killer

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