[libcxx-commits] [PATCH] D101675: [libc++] [LIBCXX-DEBUG-FIXME] Fix an iterator-invalidation issue in string::assign.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun May 2 06:52:23 PDT 2021


Quuxplusone updated this revision to Diff 342237.
Quuxplusone added a comment.

poke buildkite


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101675/new/

https://reviews.llvm.org/D101675

Files:
  libcxx/include/string
  libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp


Index: libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
===================================================================
--- libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
+++ libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: LIBCXX-DEBUG-FIXME
-
 // <string>
 
 // template<class InputIterator>
Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -1763,11 +1763,7 @@
 template <class _CharT, class _Traits, class _Allocator>
 inline
 void
-basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
-#if _LIBCPP_DEBUG_LEVEL == 2
-                                                                        __pos
-#endif
-                                                                      )
+basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
     __c_node* __c = __get_db()->__find_c_and_lock(this);
@@ -1787,6 +1783,8 @@
         }
         __get_db()->unlock();
     }
+#else
+    (void)__pos;
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 }
 
@@ -2361,12 +2359,11 @@
         size_type __sz = size();
         __grow_by(__cap, __n - __cap, __sz, 0, __sz);
     }
-    else
-        __invalidate_iterators_past(__n);
     value_type* __p = _VSTD::__to_address(__get_pointer());
     traits_type::assign(__p, __n, __c);
     traits_type::assign(__p[__n], value_type());
     __set_size(__n);
+    __invalidate_iterators_past(__n);
     return *this;
 }
 
@@ -2498,13 +2495,12 @@
             size_type __sz = size();
             __grow_by(__cap, __n - __cap, __sz, 0, __sz);
         }
-        else
-            __invalidate_iterators_past(__n);
         pointer __p = __get_pointer();
         for (; __first != __last; ++__first, ++__p)
             traits_type::assign(*__p, *__first);
         traits_type::assign(*__p, value_type());
         __set_size(__n);
+        __invalidate_iterators_past(__n);
     }
     else
     {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101675.342237.patch
Type: text/x-patch
Size: 2248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210502/54f3f734/attachment.bin>


More information about the libcxx-commits mailing list