[libcxx-commits] [libcxx] 51ba981 - [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 7 17:27:04 PST 2025
Author: A. Jiang
Date: 2025-02-08T09:26:59+08:00
New Revision: 51ba9819b40e04ef0ddbe141d3d30c32a295a0bc
URL: https://github.com/llvm/llvm-project/commit/51ba9819b40e04ef0ddbe141d3d30c32a295a0bc
DIFF: https://github.com/llvm/llvm-project/commit/51ba9819b40e04ef0ddbe141d3d30c32a295a0bc.diff
LOG: [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
`MinSequenceContainer::size` can be narrowing on 64-bit platforms, and
MSVC complains about such implicit conversion. This PR changes the
implicit conversion to explicit `static_cast`.
`min_allocator::allocate` and `min_allocator::deallocate` have
`ptrdiff_t` as the parameter type, which seems weird, because the
underlying `std::allocator`'s member functions take `size_t`. It seems
better to use `size_t` consistently.
Added:
Modified:
libcxx/test/support/MinSequenceContainer.h
libcxx/test/support/min_allocator.h
Removed:
################################################################################
diff --git a/libcxx/test/support/MinSequenceContainer.h b/libcxx/test/support/MinSequenceContainer.h
index d0e29ae40c400d3..7fee4dd0fbdc193 100644
--- a/libcxx/test/support/MinSequenceContainer.h
+++ b/libcxx/test/support/MinSequenceContainer.h
@@ -31,7 +31,7 @@ struct MinSequenceContainer {
const_iterator cbegin() const { return const_iterator(data_.data()); }
iterator end() { return begin() + size(); }
const_iterator end() const { return begin() + size(); }
- size_type size() const { return data_.size(); }
+ size_type size() const { return static_cast<size_type>(data_.size()); }
bool empty() const { return data_.empty(); }
void clear() { data_.clear(); }
diff --git a/libcxx/test/support/min_allocator.h b/libcxx/test/support/min_allocator.h
index 18f51f8072640d1..d3ee27a23bc898e 100644
--- a/libcxx/test/support/min_allocator.h
+++ b/libcxx/test/support/min_allocator.h
@@ -394,15 +394,9 @@ class min_allocator
template <class U>
TEST_CONSTEXPR_CXX20 min_allocator(min_allocator<U>) {}
- TEST_CONSTEXPR_CXX20 pointer allocate(std::ptr
diff _t n)
- {
- return pointer(std::allocator<T>().allocate(n));
- }
+ TEST_CONSTEXPR_CXX20 pointer allocate(std::size_t n) { return pointer(std::allocator<T>().allocate(n)); }
- TEST_CONSTEXPR_CXX20 void deallocate(pointer p, std::ptr
diff _t n)
- {
- std::allocator<T>().deallocate(p.ptr_, n);
- }
+ TEST_CONSTEXPR_CXX20 void deallocate(pointer p, std::size_t n) { std::allocator<T>().deallocate(p.ptr_, n); }
TEST_CONSTEXPR_CXX20 friend bool operator==(min_allocator, min_allocator) {return true;}
TEST_CONSTEXPR_CXX20 friend bool operator!=(min_allocator x, min_allocator y) {return !(x == y);}
More information about the libcxx-commits
mailing list