summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/testsuite/25_algorithms
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-11 22:24:50 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-11 22:24:50 +0000
commitd296ce8df9562ffed102d72465321f218e7e770f (patch)
treec2b99462fd063dc457a51c589c4228eef285b714 /libstdc++-v3/testsuite/25_algorithms
parent4ab283cc6dcb169aea6b063b7aeb919f11982767 (diff)
downloadppe42-gcc-d296ce8df9562ffed102d72465321f218e7e770f.tar.gz
ppe42-gcc-d296ce8df9562ffed102d72465321f218e7e770f.zip
2013-09-11 Mitsuru Kariya <kariya_mitsuru@hotmail.com>
Chris Jefferson <chris@bubblescope.net> PR libstdc++/58358 * include/bits/stl_algo.h (search_n): Fix to guarantee a number of comparisons <= number of elements in the range. * testsuite/25_algorithms/search_n/58358.cc: New. * testsuite/25_algorithms/search_n/iterator.cc: Extend. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202510 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms')
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc41
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/search_n/iterator.cc8
2 files changed, 49 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc b/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc
new file mode 100644
index 00000000000..b5ae34617f9
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc
@@ -0,0 +1,41 @@
+// Copyright (C) 2013 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+
+// 25.1.9 [lib.alg.search]
+
+#include <algorithm>
+#include <vector>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::vector<int> a{2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+ int count = 0;
+ std::search_n(a.begin(), a.end(), 10, 1,
+ [&count](int t, int u) { ++count; return t == u; });
+ VERIFY( count <= 11 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/search_n/iterator.cc b/libstdc++-v3/testsuite/25_algorithms/search_n/iterator.cc
index 27cffe74116..10616960dc2 100644
--- a/libstdc++-v3/testsuite/25_algorithms/search_n/iterator.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/search_n/iterator.cc
@@ -31,9 +31,11 @@
int array1[11] = {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0};
int array2[TEST_DEPTH];
+int pred_count;
bool
pred(int i, int j)
{
+ ++pred_count;
return i == j;
}
@@ -90,16 +92,22 @@ int main()
int* t1 = search_n(forwardcon.begin(),
forwardcon.end(), j, 1).ptr;
+ pred_count = 0;
int* t2 = search_n(forwardcon.begin(),
forwardcon.end(), j, 1, pred).ptr;
+ VERIFY(pred_count <= i);
int* t3 = search_n(bidircon.begin(),
bidircon.end(), j, 1).ptr;
+ pred_count = 0;
int* t4 = search_n(bidircon.begin(),
bidircon.end(), j, 1, pred).ptr;
+ VERIFY(pred_count <= i);
int* t5 = search_n(randomcon.begin(),
randomcon.end(), j, 1).ptr;
+ pred_count = 0;
int* t6 = search_n(randomcon.begin(),
randomcon.end(), j, 1, pred).ptr;
+ VERIFY(pred_count <= i);
VERIFY((t1 == t2) && (t2 == t3) && (t3 == t4) &&
(t4 == t5) && (t5 == t6));
}
OpenPOWER on IntegriCloud