[all-commits] [llvm/llvm-project] efa287: [libc++] Slightly simplify max_size and add new te...
Peng Liu via All-commits
all-commits at lists.llvm.org
Wed Feb 5 19:38:55 PST 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: efa287dd8a0920b20c3fe69253d8438ec8944383
https://github.com/llvm/llvm-project/commit/efa287dd8a0920b20c3fe69253d8438ec8944383
Author: Peng Liu <winner245 at hotmail.com>
Date: 2025-02-05 (Wed, 05 Feb 2025)
Changed paths:
M libcxx/include/__vector/vector_bool.h
A libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp
M libcxx/test/std/containers/sequences/vector/vector.capacity/max_size.pass.cpp
Log Message:
-----------
[libc++] Slightly simplify max_size and add new tests for vector (#119990)
This PR slightly simplifies the implementation of `vector<bool>::max_size`
and adds extensive tests for the `max_size()` function for both `vector<bool>`
and `vector<T>`. The main purposes of the new tests include:
- Verify correctness of `max_size()` under various `size_type` and
`difference_type` definitions: check that `max_size()` works properly
with allocators that have custom `size_type` and `difference_type`. This
is particularly useful for `vector<bool>`, as different `size_type` lead
to different `__storage_type` of different word lengths, resulting in
varying `max_size()` values for `vector<bool>`. Additionally, different
`difference_type` also sets different upper limit of `max_size()` for
both `vector<bool>` and `std::vector`. These tests were previously
missing.
- Eliminate incorrect implementations: Special tests are added to identify and
reject incorrect implementations of `vector<bool>::max_size` that unconditionally
return `std::min<size_type>(size-max, __internal_cap_to_external(allocator-max-size))`.
This can cause overflow in the `__internal_cap_to_external()` call and lead
to incorrect results. The new tests ensure that such incorrect
implementations are identified.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list