Apply a similar fix to <forward_list> as I did for <list> in r215210. Again, thanks to Ion GaztaƱaga for noticing this problem w.r.t LWG#526
llvm-svn: 215213
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 72d31dc..a83b195 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -1421,6 +1421,7 @@
void
forward_list<_Tp, _Alloc>::remove(const value_type& __v)
{
+ forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
iterator __e = end();
for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
{
@@ -1429,7 +1430,7 @@
iterator __j = _VSTD::next(__i, 2);
for (; __j != __e && *__j == __v; ++__j)
;
- erase_after(__i, __j);
+ __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
if (__j == __e)
break;
__i = __j;