Skip to content

Commit 4de35d1

Browse files
committed
Fix erroneous internal capacity evaluation
1 parent a629d9e commit 4de35d1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

libcxx/include/__vector/vector_bool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
115115
}
116116
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
117117
__external_cap_to_internal(size_type __n) _NOEXCEPT {
118-
return (__n - 1) / __bits_per_word + 1;
118+
return (__n + __bits_per_word - 1) / __bits_per_word;
119119
}
120120

121121
public:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ TEST_CONSTEXPR_CXX20 void test_vector_flip(std::size_t n, Allocator a) {
3232
}
3333

3434
TEST_CONSTEXPR_CXX20 bool tests() {
35+
// Test empty vectors
36+
test_vector_flip(0, std::allocator<bool>());
37+
test_vector_flip(0, min_allocator<bool>());
38+
test_vector_flip(0, test_allocator<bool>(5));
39+
3540
// Test small vectors with different allocators
3641
test_vector_flip(3, std::allocator<bool>());
3742
test_vector_flip(3, min_allocator<bool>());

0 commit comments

Comments
 (0)