llvm-project
979e9361 - [libc++] Fix improper static_cast in std::deque and __split_buffer (#119106)

Commit
290 days ago
[libc++] Fix improper static_cast in std::deque and __split_buffer (#119106) This PR addresses the improper use of `static_cast` to `size_t` where `size_type` is intended. Although the `size_type` member type of STL containers is usually a synonym of `std::size_t`, there is no guarantee that they are always equivalent. The C++ standard does not mandate this equivalence. In libc++'s implementations of `std::deque`, `std::vector`, and `__split_buffer`, the `size_type` member type is defined as `std::allocator_traits<allocator_type>::size_type`, which is either `allocator_type::size_type` if available or `std::make_unsigned<difference_type>::type`. While it is true for `std::allocator` that the `size_type` member type is `std::size_t`, for user-defined allocator types, they may mismatch. This justifies the need to replace `static_cast<size_t>` with `static_cast<size_type>` in this PR.
Author
Parents
Loading