[libcxx-commits] [libcxx] [libcxx] fixes `__split_buffer_size_layout` bugs (PR #178341)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 28 11:07:35 PST 2026


================
@@ -263,25 +261,19 @@ public:
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
   __set_valid_range(pointer __new_begin, pointer __new_end) _NOEXCEPT {
-    // Size-based __split_buffers track their size directly: we need to explicitly update the size
-    // when the front is adjusted.
-    __size_ -= __new_begin - __begin_;
     __begin_ = __new_begin;
     __set_sentinel(__new_end);
   }
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
   __set_valid_range(pointer __new_begin, size_type __new_size) _NOEXCEPT {
-    // Size-based __split_buffers track their size directly: we need to explicitly update the size
-    // when the front is adjusted.
-    __size_ -= __new_begin - __begin_;
     __begin_ = __new_begin;
     __set_sentinel(__new_size);
   }
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(pointer __new_end) _NOEXCEPT {
     _LIBCPP_ASSERT_INTERNAL(__front_cap_ <= __new_end, "__new_end cannot precede __front_cap_");
-    __size_ += __new_end - end();
+    __size_ = __new_end - __begin_;
----------------
ldionne wrote:

Ah, good catch, I wasn't fixing that in #177022. Your patch is more correct in that regard.

https://github.com/llvm/llvm-project/pull/178341


More information about the libcxx-commits mailing list