Skip to content

Commit bb2c44a

Browse files
committed
[libc++][C++03] Cherry-pick llvm#120577 and llvm#120495
1 parent 0f35df3 commit bb2c44a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libcxx/include/__cxx03/vector

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ private:
16301630
return __n * __bits_per_word;
16311631
}
16321632
_LIBCPP_HIDE_FROM_ABI static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT {
1633-
return (__n - 1) / __bits_per_word + 1;
1633+
return __n > 0 ? (__n - 1) / __bits_per_word + 1 : size_type(0);
16341634
}
16351635

16361636
public:
@@ -2142,11 +2142,13 @@ void vector<bool, _Allocator>::reserve(size_type __n) {
21422142

21432143
template <class _Allocator>
21442144
void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
2145-
if (__external_cap_to_internal(size()) > __cap()) {
2145+
if (__external_cap_to_internal(size()) < __cap()) {
21462146
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
21472147
try {
21482148
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2149-
vector(*this, allocator_type(__alloc())).swap(*this);
2149+
vector __v(*this, allocator_type(__alloc()));
2150+
if (__v.__cap() < __cap())
2151+
__v.swap(*this);
21502152
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
21512153
} catch (...) {
21522154
}

libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
// void shrink_to_fit();
1313

14-
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
15-
1614
#include <cassert>
1715
#include <climits>
1816
#include <vector>

0 commit comments

Comments
 (0)