diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2010-08-11 23:59:35 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2010-08-11 23:59:35 +0000 |
commit | afb767b41fbd9a513af007dcf8bfe93d4122fe6b (patch) | |
tree | a32f4d31130e39b531e1695206585d8fc6dd3a0d /libstdc++-v3/include | |
parent | 53d8d5c17ddc2f3eb3d813cb17e31cbc726ccede (diff) | |
download | gcc-afb767b41fbd9a513af007dcf8bfe93d4122fe6b.zip gcc-afb767b41fbd9a513af007dcf8bfe93d4122fe6b.tar.gz gcc-afb767b41fbd9a513af007dcf8bfe93d4122fe6b.tar.bz2 |
hashtable.h (_Hashtable<>::erase(const key_type&)): Use std::__addressof.
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/hashtable.h (_Hashtable<>::erase(const key_type&)):
Use std::__addressof.
* include/bits/forward_list.tcc (forward_list<>::remove): Deal
correctly with &__tmp->_M_value == &__val.
* testsuite/23_containers/forward_list/operations/remove_freed.cc:
New.
From-SVN: r163178
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/forward_list.tcc | 27 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/hashtable.h | 3 |
2 files changed, 22 insertions, 8 deletions
diff --git a/libstdc++-v3/include/bits/forward_list.tcc b/libstdc++-v3/include/bits/forward_list.tcc index a3719a8..8688f09 100644 --- a/libstdc++-v3/include/bits/forward_list.tcc +++ b/libstdc++-v3/include/bits/forward_list.tcc @@ -286,13 +286,26 @@ _GLIBCXX_BEGIN_NAMESPACE(std) remove(const _Tp& __val) { _Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head); - while (_Node* __temp = static_cast<_Node*>(__curr->_M_next)) + _Node* __extra = 0; + + while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next)) { - if (__temp->_M_value == __val) - this->_M_erase_after(__curr); - else - __curr = static_cast<_Node*>(__curr->_M_next); + if (__tmp->_M_value == __val) + { + if (std::__addressof(__tmp->_M_value) + != std::__addressof(__val)) + { + this->_M_erase_after(__curr); + continue; + } + else + __extra = __curr; + } + __curr = static_cast<_Node*>(__curr->_M_next); } + + if (__extra) + this->_M_erase_after(__extra); } template<typename _Tp, typename _Alloc> @@ -302,9 +315,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) remove_if(_Pred __pred) { _Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head); - while (_Node* __temp = static_cast<_Node*>(__curr->_M_next)) + while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next)) { - if (__pred(__temp->_M_value)) + if (__pred(__tmp->_M_value)) this->_M_erase_after(__curr); else __curr = static_cast<_Node*>(__curr->_M_next); diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index cbc67ba..a9876e1 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -1079,7 +1079,8 @@ namespace std // _GLIBCXX_RESOLVE_LIB_DEFECTS // 526. Is it undefined if a function in the standard changes // in parameters? - if (&this->_M_extract((*__slot)->_M_v) != &__k) + if (std::__addressof(this->_M_extract((*__slot)->_M_v)) + != std::__addressof(__k)) { _Node* __p = *__slot; *__slot = __p->_M_next; |