diff --git a/libcxx/include/string b/libcxx/include/string index 4f05e211919f3..67c4c537eb3b5 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -3434,8 +3434,8 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat if (__fits_in_sso(__target_capacity)) { __annotation_guard __g(*this); - traits_type::copy(std::__to_address(__get_short_pointer()), std::__to_address(__ptr), __size + 1); __set_short_size(__size); + traits_type::copy(std::__to_address(__get_short_pointer()), std::__to_address(__ptr), __size + 1); __alloc_traits::deallocate(__alloc_, __ptr, __cap); return; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp index 9ca7825a4ba92..a3b16c8da16cb 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp @@ -19,7 +19,7 @@ #include "test_macros.h" template -TEST_CONSTEXPR_CXX20 void test(S s) { +TEST_CONSTEXPR_CXX20 void test(S& s) { typename S::size_type old_cap = s.capacity(); S s0 = s; s.shrink_to_fit();