[libstdc++] Fix some header warnings

Jakub Jelinek jakub@redhat.com
Sat Dec 8 09:55:00 GMT 2007


Hi!

I've configured libstdc++ with CXXFLAGS containing -Wall, and to my surprise
these flags went all the way through into flags libstdc++ make check was
using (it seems no other make check honors such kind of flags).
This resulted in lots of test failures - I counted 72 different warning
messages.

This patch just fixes 4 of them in installed headers -
ref.second.{first,second} is size_t, so ideally we'd use %zu, but I'm afraid
there are lame targets around that don't support %zu.  Casting to long and
%lu should be good and portable enough.  Alternatively, perhaps s += ref.second.first;
could work too, but that's what the code contained originally and was
changed to sprintf a year ago or so.

The second file changes are just to shut up warning about using
x && y || a && b without parens.

2007-12-08  Jakub Jelinek  <jakub@redhat.com>

	* include/ext/throw_allocator.h (print_to_string): Change sprintf
	format to %lu and cast ref.second.{first,second} to long.

	* include/debug/safe_iterator.tcc (_M_can_advance): Add parens to
	avoid warnings.

--- libstdc++-v3/include/ext/throw_allocator.h.jj	2007-10-28 19:34:17.000000000 +0100
+++ libstdc++-v3/include/ext/throw_allocator.h	2007-12-08 10:27:25.000000000 +0100
@@ -434,11 +434,13 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
     s += buf;
     s += tab;
     s += "label: ";
-    sprintf(buf, "%u", ref.second.first);
+    unsigned long int l = static_cast<unsigned long int>(ref.second.first);
+    sprintf(buf, "%lu", l);
     s += buf;
     s += tab;
     s += "size: ";
-    sprintf(buf, "%u", ref.second.second);
+    l = static_cast<unsigned long int>(ref.second.second);
+    sprintf(buf, "%lu", l);
     s += buf;
     s += '\n';
   }
--- libstdc++-v3/include/debug/safe_iterator.tcc.jj	2006-12-08 15:58:11.000000000 +0100
+++ libstdc++-v3/include/debug/safe_iterator.tcc	2007-12-08 10:32:27.000000000 +0100
@@ -1,6 +1,6 @@
 // Debugging iterator implementation (out of line) -*- C++ -*-
 
-// Copyright (C) 2003, 2004, 2005, 2006
+// Copyright (C) 2003, 2004, 2005, 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -54,8 +54,8 @@ namespace __gnu_debug
 	    static_cast<const _Sequence*>(_M_sequence)->begin();
 	  std::pair<difference_type, _Distance_precision> __dist =
 	    this->_M_get_distance(__begin, *this);
-	  bool __ok =  (__dist.second == __dp_exact && __dist.first >= -__n
-			|| __dist.second != __dp_exact && __dist.first > 0);
+	  bool __ok = ((__dist.second == __dp_exact && __dist.first >= -__n)
+		       || (__dist.second != __dp_exact && __dist.first > 0));
 	  return __ok;
 	}
       else
@@ -64,8 +64,8 @@ namespace __gnu_debug
 	    static_cast<const _Sequence*>(_M_sequence)->end();
 	  std::pair<difference_type, _Distance_precision> __dist =
 	    this->_M_get_distance(*this, __end);
-	  bool __ok = (__dist.second == __dp_exact && __dist.first >= __n
-		       || __dist.second != __dp_exact && __dist.first > 0);
+	  bool __ok = ((__dist.second == __dp_exact && __dist.first >= __n)
+		       || (__dist.second != __dp_exact && __dist.first > 0));
 	  return __ok;
 	}
     }


	Jakub



More information about the Gcc-patches mailing list