aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2010-05-21 16:57:17 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2010-05-21 16:57:17 +0000
commit759149fbf3c844c39b283e487190eed9377b594e (patch)
tree759716ca467179a6c260bd41e88fbf2bb7ecd570
parentbdc89f9eff4e4c967107c3e88bf0737eb0a03c60 (diff)
downloadgcc-759149fbf3c844c39b283e487190eed9377b594e.zip
gcc-759149fbf3c844c39b283e487190eed9377b594e.tar.gz
gcc-759149fbf3c844c39b283e487190eed9377b594e.tar.bz2
re PR libstdc++/25306 (fill_n, generate_n assume Size is modifiable)
2010-05-21 Paolo Carlini <paolo.carlini@oracle.com> PR libstdc++/25306 * include/bits/stl_algobase.h (fill_n): Use a properly typed __niter initialized to __n. * include/bits/stl_algo.h (generate_n): Likewise. * testsuite/25_algorithms/fill_n/25306.cc: New. * testsuite/25_algorithms/generate_n/25306.cc: Likewise. From-SVN: r159677
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/stl_algo.h3
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h6
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/fill_n/25306.cc30
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/generate_n/25306.cc30
5 files changed, 75 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1eb3a31..82d13da 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2010-05-21 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR libstdc++/25306
+ * include/bits/stl_algobase.h (fill_n): Use a properly typed __niter
+ initialized to __n.
+ * include/bits/stl_algo.h (generate_n): Likewise.
+ * testsuite/25_algorithms/fill_n/25306.cc: New.
+ * testsuite/25_algorithms/generate_n/25306.cc: Likewise.
+
2010-05-21 Joseph Myers <joseph@codesourcery.com>
* acinclude.m4 (GLIBCXX_ENABLE_CLOCALE): Use GNU locale model for
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index 5b4991e..fe2edb9 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -4844,7 +4844,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
// "the type returned by a _Generator"
__typeof__(__gen())>)
- for (; __n > 0; --__n, ++__first)
+ for (__decltype(__n + 0) __niter = __n;
+ __niter > 0; --__niter, ++__first)
*__first = __gen();
return __first;
}
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index e925404..0489c41 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -748,7 +748,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
__fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
{
- for (; __n > 0; --__n, ++__first)
+ for (__decltype(__n + 0) __niter = __n;
+ __niter > 0; --__niter, ++__first)
*__first = __value;
return __first;
}
@@ -759,7 +760,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
{
const _Tp __tmp = __value;
- for (; __n > 0; --__n, ++__first)
+ for (__decltype(__n + 0) __niter = __n;
+ __niter > 0; --__niter, ++__first)
*__first = __tmp;
return __first;
}
diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/25306.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/25306.cc
new file mode 100644
index 0000000..37ccd7c
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/25306.cc
@@ -0,0 +1,30 @@
+// { dg-do compile }
+
+// Copyright (C) 2010 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/>.
+
+#include <algorithm>
+
+struct Size
+{
+ operator int() { return 0; }
+private:
+ void operator=(Size&);
+};
+
+// libstdc++/25306
+template int* std::fill_n(int*, Size, const int&);
diff --git a/libstdc++-v3/testsuite/25_algorithms/generate_n/25306.cc b/libstdc++-v3/testsuite/25_algorithms/generate_n/25306.cc
new file mode 100644
index 0000000..f73ff3d
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/generate_n/25306.cc
@@ -0,0 +1,30 @@
+// { dg-do compile }
+
+// Copyright (C) 2010 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/>.
+
+#include <algorithm>
+
+struct Size
+{
+ operator int() { return 0; }
+private:
+ void operator=(Size&);
+};
+
+// libstdc++/25306
+template int* std::generate_n(int*, Size, int (*)());