mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 06:36:46 +00:00

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.