Skip to content

Commit 885d70b

Browse files
committed
Fix a bug in vector<bool> due to integral promotion
1 parent 7163603 commit 885d70b

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

libcxx/include/__cxx03/string

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
24832483
__throw_length_error();
24842484
pointer __old_p = __get_pointer();
24852485
size_type __cap =
2486-
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
2486+
__old_cap < __ms / 2 - __alignment
2487+
? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
2488+
: __ms - 1;
24872489
__annotate_delete();
24882490
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
24892491
pointer __p = __allocation.ptr;
@@ -2526,7 +2528,9 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
25262528
__throw_length_error();
25272529
pointer __old_p = __get_pointer();
25282530
size_type __cap =
2529-
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
2531+
__old_cap < __ms / 2 - __alignment
2532+
? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
2533+
: __ms - 1;
25302534
__annotate_delete();
25312535
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
25322536
pointer __p = __allocation.ptr;

libcxx/include/__cxx03/vector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
23282328
const size_type __cap = capacity();
23292329
if (__cap >= __ms / 2)
23302330
return __ms;
2331-
return std::max(2 * __cap, __align_it(__new_size));
2331+
return std::max<size_type>(2 * __cap, __align_it(__new_size));
23322332
}
23332333

23342334
// Default constructs __n objects starting at __end_

libcxx/include/__vector/vector_bool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
527527
const size_type __cap = capacity();
528528
if (__cap >= __ms / 2)
529529
return __ms;
530-
return std::max(2 * __cap, __align_it(__new_size));
530+
return std::max<size_type>(2 * __cap, __align_it(__new_size));
531531
}
532532

533533
// Default constructs __n objects starting at __end_

libcxx/include/string

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
25182518
__throw_length_error();
25192519
pointer __old_p = __get_pointer();
25202520
size_type __cap =
2521-
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
2521+
__old_cap < __ms / 2 - __alignment
2522+
? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
2523+
: __ms - 1;
25222524
__annotate_delete();
25232525
auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
25242526
auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);

0 commit comments

Comments
 (0)