diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2011-09-27 02:39:34 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2011-09-27 02:39:34 +0000 |
commit | a7cee01d32cdbe912b32ad113b569b39a0e95445 (patch) | |
tree | b6525343983bf3112c8c0936acc632df1f36f60b /libstdc++-v3/include/bits | |
parent | b92edfe52d92baaf258a9d3234a964411a2b94b7 (diff) | |
download | gcc-a7cee01d32cdbe912b32ad113b569b39a0e95445.tar.gz |
re PR libstdc++/50529 ([C++0x] std::vector::erase invokes undefined behavior with empty range)
2011-09-26 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/50529
* include/bits/vector.tcc (vector<>::erase(iterator, iterator)):
Fix to do nothing if the range is empty.
* include/bits/stl_bvector.h: Likewise.
* include/bits/deque.tcc: Likewise.
* include/debug/vector: Adjust.
* include/debug/deque: Likewise.
* testsuite/23_containers/vector/modifiers/erase/50529.cc: New.
* testsuite/23_containers/deque/modifiers/erase/50529.cc: Likewise.
* testsuite/23_containers/deque/modifiers/erase/3.cc: Adjust.
From-SVN: r179234
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r-- | libstdc++-v3/include/bits/deque.tcc | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_bvector.h | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/vector.tcc | 9 |
3 files changed, 11 insertions, 5 deletions
diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index fab79157cdb..5b56875b493 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -218,7 +218,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER deque<_Tp, _Alloc>:: erase(iterator __first, iterator __last) { - if (__first == begin() && __last == end()) + if (__first == __last) + return __first; + else if (__first == begin() && __last == end()) { clear(); return end(); diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 22443f4a4c1..bddecb0d4c5 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -838,7 +838,8 @@ template<typename _Alloc> iterator erase(iterator __first, iterator __last) { - _M_erase_at_end(std::copy(__last, end(), __first)); + if (__first != __last) + _M_erase_at_end(std::copy(__last, end(), __first)); return __first; } diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index ba98c7cb07e..b74684228c1 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -147,9 +147,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER vector<_Tp, _Alloc>:: erase(iterator __first, iterator __last) { - if (__last != end()) - _GLIBCXX_MOVE3(__last, end(), __first); - _M_erase_at_end(__first.base() + (end() - __last)); + if (__first != __last) + { + if (__last != end()) + _GLIBCXX_MOVE3(__last, end(), __first); + _M_erase_at_end(__first.base() + (end() - __last)); + } return __first; } |