commit 566623def309c70387e41da2346ff89aa7619b13
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed May 7 12:17:41 2014 +0100
PR libstdc++/61086
* include/bits/stl_iterator.h (__normal_iterator::_M_const_cast):
Remove.
* include/bits/stl_vector.h (vector::insert, vector::erase): Use
arithmetic to obtain a mutable iterator from const_iterator.
* include/bits/vector.tcc (vector::insert): Likewise.
* include/debug/vector (vector::erase): Likewise.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
Adjust dg-error line number.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
Likewise.
@@ -736,21 +736,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Container>::__type>& __i) _GLIBCXX_NOEXCEPT
: _M_current(__i.base()) { }
-#if __cplusplus >= 201103L
- __normal_iterator<typename _Container::pointer, _Container>
- _M_const_cast() const noexcept
- {
- using _PTraits = std::pointer_traits<typename _Container::pointer>;
- return __normal_iterator<typename _Container::pointer, _Container>
- (_PTraits::pointer_to(const_cast<typename _PTraits::element_type&>
- (*_M_current)));
- }
-#else
- __normal_iterator
- _M_const_cast() const
- { return *this; }
-#endif
-
// Forward iterator requirements
reference
operator*() const _GLIBCXX_NOEXCEPT
@@ -1051,7 +1051,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
insert(const_iterator __position, size_type __n, const value_type& __x)
{
difference_type __offset = __position - cbegin();
- _M_fill_insert(__position._M_const_cast(), __n, __x);
+ _M_fill_insert(begin() + __offset, __n, __x);
return begin() + __offset;
}
#else
@@ -1096,7 +1096,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_InputIterator __last)
{
difference_type __offset = __position - cbegin();
- _M_insert_dispatch(__position._M_const_cast(),
+ _M_insert_dispatch(begin() + __offset,
__first, __last, __false_type());
return begin() + __offset;
}
@@ -1144,10 +1144,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
iterator
#if __cplusplus >= 201103L
erase(const_iterator __position)
+ { return _M_erase(begin() + (__position - cbegin())); }
#else
erase(iterator __position)
+ { return _M_erase(__position); }
#endif
- { return _M_erase(__position._M_const_cast()); }
/**
* @brief Remove a range of elements.
@@ -1170,10 +1171,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
iterator
#if __cplusplus >= 201103L
erase(const_iterator __first, const_iterator __last)
+ {
+ const auto __beg = begin();
+ const auto __cbeg = cbegin();
+ return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
+ }
#else
erase(iterator __first, iterator __last)
+ { return _M_erase(__first, __last); }
#endif
- { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
/**
* @brief Swaps data with another %vector.
@@ -121,14 +121,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
else
{
#if __cplusplus >= 201103L
+ const auto __pos = begin() + (__position - cbegin());
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
{
_Tp __x_copy = __x;
- _M_insert_aux(__position._M_const_cast(), std::move(__x_copy));
+ _M_insert_aux(__pos, std::move(__x_copy));
}
else
+ _M_insert_aux(__pos, __x);
+#else
+ _M_insert_aux(__position, __x);
#endif
- _M_insert_aux(__position._M_const_cast(), __x);
}
return iterator(this->_M_impl._M_start + __n);
}
@@ -307,7 +310,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
++this->_M_impl._M_finish;
}
else
- _M_insert_aux(__position._M_const_cast(),
+ _M_insert_aux(begin() + (__position - cbegin()),
std::forward<_Args>(__args)...);
return iterator(this->_M_impl._M_start + __n);
}
@@ -647,7 +647,7 @@ namespace __debug
}
else
#if __cplusplus >= 201103L
- return iterator(__first.base()._M_const_cast(), this);
+ return begin() + (__first.base() - cbegin().base());
#else
return __first;
#endif
@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1320 }
+// { dg-error "no matching" "" { target *-*-* } 1326 }
#include <vector>
@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1246 }
+// { dg-error "no matching" "" { target *-*-* } 1252 }
#include <vector>
@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1246 }
+// { dg-error "no matching" "" { target *-*-* } 1252 }
#include <vector>
#include <utility>
@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1361 }
+// { dg-error "no matching" "" { target *-*-* } 1367 }
#include <vector>