[libc++][test] Fix size_type issues with MinSequenceContainer and min_allocator#126267
Merged
frederick-vs-ja merged 1 commit intollvm:mainfrom Feb 8, 2025
Merged
Conversation
Member
|
@llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) Changes
Full diff: https://github.com/llvm/llvm-project/pull/126267.diff 2 Files Affected:
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);
}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
... and `min_allocator`
5071d8a to
15bfb29
Compare
philnik777
approved these changes
Feb 7, 2025
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
… `min_allocator` (llvm#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MinSequenceContainer::sizecan be narrowing on 64-bit platforms, and MSVC complains about such implicit conversion. This PR changes the implicit conversion to explicitstatic_cast.min_allocator::allocateandmin_allocator::deallocatehaveptrdiff_tas the parameter type, which seems weird, because the underlyingstd::allocator's member functions takesize_t. It seems better to usesize_tconsistently.