summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits
diff options
context:
space:
mode:
authorPaolo Carlini <paolo@gcc.gnu.org>2011-08-18 16:32:23 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2011-08-18 16:32:23 +0000
commit6ba30237b918e2d8c35bf481767ccd525499625e (patch)
treef55f3e9a1fac35f32e7847001fe076ec7532f81c /libstdc++-v3/include/bits
parentdf385b9c2b6e05ec699eba7fbf8fc958a17f7a03 (diff)
downloadgcc-6ba30237b918e2d8c35bf481767ccd525499625e.tar.gz
re PR libstdc++/50119 ([C++0x] copy_n advances InputIterator one more time than necessary)
2011-08-18 Paolo Carlini <paolo.carlini@oracle.com> PR libstdc++/50119 * include/bits/stl_algo.h (__copy_n(_InputIterator, _Size, _OutputIterator, input_iterator_tag)): Fix. * testsuite/25_algorithms/copy_n/50119.cc: New. From-SVN: r177871
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r--libstdc++-v3/include/bits/stl_algo.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index ba49228dfb4..10c7e2d0756 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -979,11 +979,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__copy_n(_InputIterator __first, _Size __n,
_OutputIterator __result, input_iterator_tag)
{
- for (; __n > 0; --__n)
+ if (__n > 0)
{
- *__result = *__first;
- ++__first;
- ++__result;
+ while (true)
+ {
+ *__result = *__first;
+ ++__result;
+ if (--__n > 0)
+ ++__first;
+ else
+ break;
+ }
}
return __result;
}