From e31f7b6da4504841c1e56c1caf03eec7e851253c Mon Sep 17 00:00:00 2001 From: dim Date: Mon, 11 Aug 2014 20:37:03 +0000 Subject: [PATCH] MFC r269740: Pull in r214736 from upstream libc++ trunk (by Marshall Clow): Fix PR#20520 - predicate called too many times in list::remove_if. Add tests for list, forward_list, and the std::remove_if algorithm This fixes an issue where std::list<>::remove_if() and remove() could erroneously visit elements twice. Reported by: Dominic Fandrey PR: 192303 git-svn-id: svn://svn.freebsd.org/base/stable/10@269836 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- contrib/libc++/include/list | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/libc++/include/list b/contrib/libc++/include/list index 800a1a3f5..7ccc778c9 100644 --- a/contrib/libc++/include/list +++ b/contrib/libc++/include/list @@ -2046,6 +2046,8 @@ list<_Tp, _Alloc>::remove(const value_type& __x) for (; __j != __e && *__j == __x; ++__j) ; __i = erase(__i, __j); + if (__i != __e) + __i = _VSTD::next(__i); } else ++__i; @@ -2065,6 +2067,8 @@ list<_Tp, _Alloc>::remove_if(_Pred __pred) for (; __j != __e && __pred(*__j); ++__j) ; __i = erase(__i, __j); + if (__i != __e) + __i = _VSTD::next(__i); } else ++__i; -- 2.45.0