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]

[Patch] Fix libstdc++/11400


Hi,

the below, privately suggested by Nathan, is a minimal fix for the PR.
Seems the correct approach to me too! In fact iterator_traits<>difference_type
is already used elsewhere in the same file for counting.


Tested x86-linux. Ok with everyone?

Paolo.

//////////////
2003-09-27  Nathan Myers  <ncm@cantrip.org>
	    Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/11400
	* include/bits/stl_algo.h (search_n):
	Use iterator_traits<>::difference_type for __n.
	* testsuite/25_algorithms/search_n/11400.cc: New, from the PR.
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	2003-07-15 09:30:19.000000000 +0200
+++ libstdc++-v3/include/bits/stl_algo.h	2003-09-27 12:04:33.000000000 +0200
@@ -609,7 +609,7 @@
       else {
 	__first = std::find(__first, __last, __val);
 	while (__first != __last) {
-	  _Integer __n = __count - 1;
+	  typename iterator_traits<_ForwardIterator>::difference_type __n = __count - 1;
 	  _ForwardIterator __i = __first;
 	  ++__i;
 	  while (__i != __last && __n != 0 && *__i == __val) {
@@ -661,7 +661,7 @@
 	  ++__first;
 	}
 	while (__first != __last) {
-	  _Integer __n = __count - 1;
+	  typename iterator_traits<_ForwardIterator>::difference_type __n = __count - 1;
 	  _ForwardIterator __i = __first;
 	  ++__i;
 	  while (__i != __last && __n != 0 && __binary_pred(*__i, __val)) {
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/search_n/11400.cc libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/search_n/11400.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc	2003-09-27 12:26:19.000000000 +0200
@@ -0,0 +1,33 @@
+// Copyright (C) 2003 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 25.1.9 [lib.alg.search]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <functional>
+
+struct Integral { operator int() const; };
+
+namespace std
+{
+  template int* search_n (int*, int*, Integral, const int&);
+  template int* search_n (int*, int*, Integral, const int&, greater<int>);
+}
+

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