From 885d70b53f6ca4b0097a62858cf374bb3bdf7ba8 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Thu, 12 Dec 2024 21:33:15 -0500 Subject: [PATCH] Fix a bug in vector due to integral promotion --- libcxx/include/__cxx03/string | 8 ++++++-- libcxx/include/__cxx03/vector | 2 +- libcxx/include/__vector/vector_bool.h | 2 +- libcxx/include/string | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libcxx/include/__cxx03/string b/libcxx/include/__cxx03/string index c4431dcb04d41e..c29f74290bd416 100644 --- a/libcxx/include/__cxx03/string +++ b/libcxx/include/__cxx03/string @@ -2483,7 +2483,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__ __throw_length_error(); pointer __old_p = __get_pointer(); size_type __cap = - __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1; + __old_cap < __ms / 2 - __alignment + ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) + : __ms - 1; __annotate_delete(); auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); pointer __p = __allocation.ptr; @@ -2526,7 +2528,9 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait __throw_length_error(); pointer __old_p = __get_pointer(); size_type __cap = - __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1; + __old_cap < __ms / 2 - __alignment + ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) + : __ms - 1; __annotate_delete(); auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); pointer __p = __allocation.ptr; diff --git a/libcxx/include/__cxx03/vector b/libcxx/include/__cxx03/vector index 6ee35b4e36258f..80da74ded67b7a 100644 --- a/libcxx/include/__cxx03/vector +++ b/libcxx/include/__cxx03/vector @@ -2328,7 +2328,7 @@ vector::__recommend(size_type __new_size) const { const size_type __cap = capacity(); if (__cap >= __ms / 2) return __ms; - return std::max(2 * __cap, __align_it(__new_size)); + return std::max(2 * __cap, __align_it(__new_size)); } // Default constructs __n objects starting at __end_ diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h index 36eb7f350ac406..26b172af9138db 100644 --- a/libcxx/include/__vector/vector_bool.h +++ b/libcxx/include/__vector/vector_bool.h @@ -527,7 +527,7 @@ vector::__recommend(size_type __new_size) const { const size_type __cap = capacity(); if (__cap >= __ms / 2) return __ms; - return std::max(2 * __cap, __align_it(__new_size)); + return std::max(2 * __cap, __align_it(__new_size)); } // Default constructs __n objects starting at __end_ diff --git a/libcxx/include/string b/libcxx/include/string index 17bf4b3b98bf34..911b67cfcf26e8 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -2518,7 +2518,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__ __throw_length_error(); pointer __old_p = __get_pointer(); size_type __cap = - __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1; + __old_cap < __ms / 2 - __alignment + ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) + : __ms - 1; __annotate_delete(); auto __guard = std::__make_scope_guard(__annotate_new_size(*this)); auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);