[libcxx-commits] [libcxx] [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (PR #126267)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 7 09:15:21 PST 2025
https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/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.
>From 5071d8abaf0bcc2c81127c9b015ff7ff1af9cdf6 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sat, 8 Feb 2025 01:10:31 +0800
Subject: [PATCH] [libc++][test] `size_type` issues with `MinSequenceContainer`
and...
... `min_allocator`
---
libcxx/test/support/MinSequenceContainer.h | 2 +-
libcxx/test/support/min_allocator.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
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..beee83feb95f1c0 100644
--- a/libcxx/test/support/min_allocator.h
+++ b/libcxx/test/support/min_allocator.h
@@ -394,12 +394,12 @@ class min_allocator
template <class U>
TEST_CONSTEXPR_CXX20 min_allocator(min_allocator<U>) {}
- TEST_CONSTEXPR_CXX20 pointer allocate(std::ptrdiff_t 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::ptrdiff_t n)
+ TEST_CONSTEXPR_CXX20 void deallocate(pointer p, std::size_t n)
{
std::allocator<T>().deallocate(p.ptr_, n);
}
More information about the libcxx-commits
mailing list