diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1694,6 +1694,15 @@ return *this; } + void __finish_replace(size_type& __sz, size_type& __n1, size_type& __n2, value_type*& __p) { + // __sz += __n2 - __n1; in this and the below function below can cause unsigned + // integer overflow, but this is a safe operation, so we disable the check. + __sz += __n2 - __n1; + __set_size(__sz); + __invalidate_iterators_past(__sz); + traits_type::assign(__p[__sz], value_type()); + } + _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type); @@ -2996,7 +3005,8 @@ { traits_type::move(__p + __pos, __s, __n2); traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); - goto __finish; + __finish_replace(__sz, __n1, __n2, __p); + return *this; } if (__p + __pos < __s && __s < __p + __sz) { @@ -3015,13 +3025,7 @@ } } traits_type::move(__p + __pos, __s, __n2); -__finish: -// __sz += __n2 - __n1; in this and the below function below can cause unsigned -// integer overflow, but this is a safe operation, so we disable the check. - __sz += __n2 - __n1; - __set_size(__sz); - __invalidate_iterators_past(__sz); - traits_type::assign(__p[__sz], value_type()); + __finish_replace(__sz, __n1, __n2, __p); } else __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);