Skip to content

Commit ba0ec7c

Browse files
committed
Fix a bug in vector<bool> due to integral promotion
1 parent 7687548 commit ba0ec7c

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

libcxx/include/__cxx03/string

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ public:
10251025
// Turning off ASan instrumentation for variable initialization with _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
10261026
// does not work consistently during initialization of __r_, so we instead unpoison __str's memory manually first.
10271027
// __str's memory needs to be unpoisoned only in the case where it's a short string.
1028-
: __r_([](basic_string& __s) -> decltype(__s.__r_)&& {
1028+
: __r_([](basic_string& __s) -> decltype(__s.__r_) && {
10291029
if (!__s.__is_long())
10301030
__s.__annotate_delete();
10311031
return std::move(__s.__r_);
@@ -2277,8 +2277,8 @@ template <class _CharT,
22772277
class _Traits,
22782278
class _Allocator = allocator<_CharT>,
22792279
class = enable_if_t<__is_allocator<_Allocator>::value> >
2280-
explicit basic_string(basic_string_view<_CharT, _Traits>,
2281-
const _Allocator& = _Allocator()) -> basic_string<_CharT, _Traits, _Allocator>;
2280+
explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
2281+
-> basic_string<_CharT, _Traits, _Allocator>;
22822282

22832283
template <class _CharT,
22842284
class _Traits,
@@ -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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ public:
10471047
// Turning off ASan instrumentation for variable initialization with _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
10481048
// does not work consistently during initialization of __r_, so we instead unpoison __str's memory manually first.
10491049
// __str's memory needs to be unpoisoned only in the case where it's a short string.
1050-
: __rep_([](basic_string& __s) -> decltype(__s.__rep_)&& {
1050+
: __rep_([](basic_string& __s) -> decltype(__s.__rep_) && {
10511051
if (!__s.__is_long())
10521052
__s.__annotate_delete();
10531053
return std::move(__s.__rep_);
@@ -2312,8 +2312,8 @@ template <class _CharT,
23122312
class _Traits,
23132313
class _Allocator = allocator<_CharT>,
23142314
class = enable_if_t<__is_allocator<_Allocator>::value> >
2315-
explicit basic_string(basic_string_view<_CharT, _Traits>,
2316-
const _Allocator& = _Allocator()) -> basic_string<_CharT, _Traits, _Allocator>;
2315+
explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
2316+
-> basic_string<_CharT, _Traits, _Allocator>;
23172317

23182318
template <class _CharT,
23192319
class _Traits,
@@ -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)