Skip to content

Commit

Permalink
Fix a bug in vector<bool> due to integral promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
winner245 committed Dec 13, 2024
1 parent 7163603 commit 885d70b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions libcxx/include/__cxx03/string
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
: __ms - 1;
__annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
Expand Down Expand Up @@ -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<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
: __ms - 1;
__annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/vector
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ vector<bool, _Allocator>::__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<size_type>(2 * __cap, __align_it(__new_size));
}

// Default constructs __n objects starting at __end_
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__vector/vector_bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ vector<bool, _Allocator>::__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<size_type>(2 * __cap, __align_it(__new_size));
}

// Default constructs __n objects starting at __end_
Expand Down
4 changes: 3 additions & 1 deletion libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_type>(__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);
Expand Down

0 comments on commit 885d70b

Please sign in to comment.