aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Dumont <fdumont@gcc.gnu.org>2018-06-13 20:27:26 +0000
committerFrançois Dumont <fdumont@gcc.gnu.org>2018-06-13 20:27:26 +0000
commiteb04ee1d0f23b14c251a850f2a26429d324b1f6f (patch)
tree30635dfd4a3cb91099144aed2e26f667c1567867
parent3b07c0e5e45a5594e9929adf898736af7b6839da (diff)
downloadgcc-eb04ee1d0f23b14c251a850f2a26429d324b1f6f.zip
gcc-eb04ee1d0f23b14c251a850f2a26429d324b1f6f.tar.gz
gcc-eb04ee1d0f23b14c251a850f2a26429d324b1f6f.tar.bz2
2018-06-13 François Dumont <fdumont@gcc.gnu.org>
* include/debug/helper_functions.h (__gnu_debug::_Safe_iterator<>): Add declaration. (__can_advance(_Ite, _Size)): New. (__can_advance(const _Safe_iterator<>&, _Size)): Overload declaration. * include/debug/functions.h (__gnu_debug::_Safe_iterator<>): Remove declaration. * include/debug/stl_iterator.h (__can_advance(const _Safe_iterator<>&)): New definition. * include/debug/stl_iterator.h (__can_advance(const std::reverse_iterator<>&, _Size)): New. (__can_advance(const std::move_iterator<>&, _Size)): New. * include/debug/macros.h (__glibcxx_check_can_increment): New. * include/debug/debug.h (__glibcxx_requires_can_increment): New. * include/bits/stl_algobase.h (fill_n): Use latter. * testsuite/25_algorithms/fill_n/2.cc: New. * testsuite/25_algorithms/fill_n/debug/1_neg.cc: New. * testsuite/25_algorithms/fill_n/debug/2_neg.cc: New. * testsuite/25_algorithms/fill_n/debug/3_neg.cc: New. * testsuite/25_algorithms/fill_n/debug/4_neg.cc: New. From-SVN: r261566
-rw-r--r--libstdc++-v3/ChangeLog20
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h1
-rw-r--r--libstdc++-v3/include/debug/debug.h3
-rw-r--r--libstdc++-v3/include/debug/functions.h3
-rw-r--r--libstdc++-v3/include/debug/helper_functions.h13
-rw-r--r--libstdc++-v3/include/debug/macros.h7
-rw-r--r--libstdc++-v3/include/debug/safe_iterator.h5
-rw-r--r--libstdc++-v3/include/debug/stl_iterator.h10
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/fill_n/2.cc46
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/fill_n/debug/1_neg.cc39
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/fill_n/debug/2_neg.cc39
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/fill_n/debug/3_neg.cc39
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/fill_n/debug/4_neg.cc43
13 files changed, 265 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 9f33999..223b327 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -13,6 +13,26 @@
2018-06-13 François Dumont <fdumont@gcc.gnu.org>
+ * include/debug/helper_functions.h
+ (__gnu_debug::_Safe_iterator<>): Add declaration.
+ (__can_advance(_Ite, _Size)): New.
+ (__can_advance(const _Safe_iterator<>&, _Size)): Overload declaration.
+ * include/debug/functions.h
+ (__gnu_debug::_Safe_iterator<>): Remove declaration.
+ * include/debug/stl_iterator.h
+ (__can_advance(const _Safe_iterator<>&)): New definition.
+ * include/debug/stl_iterator.h
+ (__can_advance(const std::reverse_iterator<>&, _Size)): New.
+ (__can_advance(const std::move_iterator<>&, _Size)): New.
+ * include/debug/macros.h (__glibcxx_check_can_increment): New.
+ * include/debug/debug.h (__glibcxx_requires_can_increment): New.
+ * include/bits/stl_algobase.h (fill_n): Use latter.
+ * testsuite/25_algorithms/fill_n/2.cc: New.
+ * testsuite/25_algorithms/fill_n/debug/1_neg.cc: New.
+ * testsuite/25_algorithms/fill_n/debug/2_neg.cc: New.
+ * testsuite/25_algorithms/fill_n/debug/3_neg.cc: New.
+ * testsuite/25_algorithms/fill_n/debug/4_neg.cc: New.
+
* include/debug/debug.h (__glibcxx_requires_can_increment_range): New.
(__glibcxx_requires_can_decrement_range): New.
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index 877f32b..022a3f1 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -783,6 +783,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
// concept requirements
__glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
+ __glibcxx_requires_can_increment(__first, __n);
return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
}
diff --git a/libstdc++-v3/include/debug/debug.h b/libstdc++-v3/include/debug/debug.h
index d055dcb..f157a6d 100644
--- a/libstdc++-v3/include/debug/debug.h
+++ b/libstdc++-v3/include/debug/debug.h
@@ -62,6 +62,7 @@ namespace __gnu_debug
# define __glibcxx_requires_cond(_Cond,_Msg)
# define __glibcxx_requires_valid_range(_First,_Last)
+# define __glibcxx_requires_can_increment(_First,_Size)
# define __glibcxx_requires_can_increment_range(_First1,_Last1,_First2)
# define __glibcxx_requires_can_decrement_range(_First1,_Last1,_First2)
# define __glibcxx_requires_sorted(_First,_Last)
@@ -88,6 +89,8 @@ namespace __gnu_debug
# define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg)
# define __glibcxx_requires_valid_range(_First,_Last) \
__glibcxx_check_valid_range(_First,_Last)
+# define __glibcxx_requires_can_increment(_First,_Size) \
+ __glibcxx_check_can_increment(_First,_Size)
# define __glibcxx_requires_can_increment_range(_First1,_Last1,_First2) \
__glibcxx_check_can_increment_range(_First1,_Last1,_First2)
# define __glibcxx_requires_can_decrement_range(_First1,_Last1,_First2) \
diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h
index 3a2ba74..41519b2 100644
--- a/libstdc++-v3/include/debug/functions.h
+++ b/libstdc++-v3/include/debug/functions.h
@@ -40,9 +40,6 @@
namespace __gnu_debug
{
- template<typename _Iterator, typename _Sequence>
- class _Safe_iterator;
-
template<typename _Sequence>
struct _Insert_range_from_self_is_safe
{ enum { __value = 0 }; };
diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h
index 94d5016..2073df9 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -37,6 +37,9 @@
namespace __gnu_debug
{
+ template<typename _Iterator, typename _Sequence>
+ class _Safe_iterator;
+
/** The precision to which we can calculate the distance between
* two iterators.
*/
@@ -164,6 +167,16 @@ namespace __gnu_debug
return __valid_range(__first, __last, __dist);
}
+ // Fallback method, always ok.
+ template<typename _InputIterator, typename _Size>
+ inline bool
+ __can_advance(_InputIterator, _Size)
+ { return true; }
+
+ template<typename _Iterator, typename _Sequence, typename _Size>
+ bool
+ __can_advance(const _Safe_iterator<_Iterator, _Sequence>&, _Size);
+
#if __cplusplus < 201103L
// Helper struct to detect random access safe iterators.
template<typename _Iterator>
diff --git a/libstdc++-v3/include/debug/macros.h b/libstdc++-v3/include/debug/macros.h
index a88faf9..44f48b0 100644
--- a/libstdc++-v3/include/debug/macros.h
+++ b/libstdc++-v3/include/debug/macros.h
@@ -87,6 +87,13 @@ _GLIBCXX_DEBUG_VERIFY(_First != _Last, \
._M_iterator(_First, #_First) \
._M_iterator(_Last, #_Last))
+// Verify that [_First, _First + _Size) forms a valid range.
+#define __glibcxx_check_can_increment(_First,_Size) \
+_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__can_advance(_First, _Size), \
+ _M_message(__gnu_debug::__msg_iter_subscript_oob) \
+ ._M_iterator(_First, #_First) \
+ ._M_integer(_Size, #_Size))
+
#define __glibcxx_check_can_increment_range(_First1,_Last1,_First2) \
do \
{ \
diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h
index 3a53ab7..7ed2b93 100644
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -862,6 +862,11 @@ namespace __gnu_debug
return __res;
}
+ template<typename _Iterator, typename _Sequence, typename _Size>
+ inline bool
+ __can_advance(const _Safe_iterator<_Iterator, _Sequence>& __it, _Size __n)
+ { return __it._M_can_advance(__n); }
+
#if __cplusplus < 201103L
template<typename _Iterator, typename _Sequence>
struct __is_safe_random_iterator<_Safe_iterator<_Iterator, _Sequence> >
diff --git a/libstdc++-v3/include/debug/stl_iterator.h b/libstdc++-v3/include/debug/stl_iterator.h
index 21eac76..a6a2a76 100644
--- a/libstdc++-v3/include/debug/stl_iterator.h
+++ b/libstdc++-v3/include/debug/stl_iterator.h
@@ -47,6 +47,11 @@ namespace __gnu_debug
const std::reverse_iterator<_Iterator>& __last)
{ return __get_distance(__last.base(), __first.base()); }
+ template<typename _Iterator, typename _Size>
+ inline bool
+ __can_advance(const std::reverse_iterator<_Iterator>& __it, _Size __n)
+ { return __can_advance(__it.base(), -__n); }
+
#if __cplusplus < 201103L
template<typename _Iterator>
struct __is_safe_random_iterator<std::reverse_iterator<_Iterator> >
@@ -96,6 +101,11 @@ namespace __gnu_debug
const std::move_iterator<_Iterator>& __last)
{ return __get_distance(__first.base(), __last.base()); }
+ template<typename _Iterator, typename _Size>
+ inline bool
+ __can_advance(const std::move_iterator<_Iterator>& __it, _Size __n)
+ { return __can_advance(__it.base(), __n); }
+
template<typename _Iterator>
inline auto
__unsafe(const std::move_iterator<_Iterator>& __it)
diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/2.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/2.cc
new file mode 100644
index 0000000..6e18032
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/2.cc
@@ -0,0 +1,46 @@
+// Copyright (C) 2018 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/>.
+
+// 25.2.5 [lib.alg.fill] Fill_n.
+
+// { dg-require-debug-mode "" }
+
+#include <algorithm>
+#include <vector>
+
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::vector<int> ref;
+ ref.push_back(1);
+ ref.push_back(2);
+
+ std::vector<std::vector<int>> vvect;
+ vvect.push_back(std::vector<int>());
+ vvect.push_back(std::vector<int>());
+
+ VERIFY( std::fill_n(vvect.begin(), 2, ref) == vvect.end() );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/1_neg.cc
new file mode 100644
index 0000000..45a88fe
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/1_neg.cc
@@ -0,0 +1,39 @@
+// Copyright (C) 2018 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/>.
+
+// 25.2.5 [lib.alg.fill] Fill_n.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <algorithm>
+#include <vector>
+
+void
+test01()
+{
+ std::vector<int> vect;
+ vect.push_back(1);
+ std::fill_n(vect.begin(), 2, 0);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/2_neg.cc
new file mode 100644
index 0000000..3738ae6
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/2_neg.cc
@@ -0,0 +1,39 @@
+// Copyright (C) 2018 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/>.
+
+// 25.2.5 [lib.alg.fill] Fill_n.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <algorithm>
+#include <vector>
+
+void
+test01()
+{
+ std::vector<int> vect;
+ vect.push_back(1);
+ std::fill_n(vect.rbegin(), 2, 0);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/3_neg.cc
new file mode 100644
index 0000000..1497dbb
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/3_neg.cc
@@ -0,0 +1,39 @@
+// Copyright (C) 2018 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/>.
+
+// 25.2.5 [lib.alg.fill] Fill_n.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <algorithm>
+#include <list>
+
+void
+test01()
+{
+ std::list<int> l;
+ l.push_back(1);
+ std::fill_n(l.begin(), 2, 0);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/4_neg.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/4_neg.cc
new file mode 100644
index 0000000..70c4a29
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/debug/4_neg.cc
@@ -0,0 +1,43 @@
+// Copyright (C) 2018 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/>.
+
+// 25.2.5 [lib.alg.fill] Fill_n.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-require-debug-mode "" }
+
+#include <algorithm>
+#include <list>
+
+void
+test01()
+{
+ std::list<int> l;
+ l.push_back(1);
+ l.push_back(2);
+
+ std::list<int>::iterator it = l.begin();
+ ++it;
+ std::fill_n(it, 2, 0);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}