[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:23:21 PST 2025


https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/126267

>From 15bfb2989bd5997d82f75772cb3eefef7408709d Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sat, 8 Feb 2025 01:22:22 +0800
Subject: [PATCH] [libc++][test] Fix `size_type` issues with
 `MinSequenceContainer`...

... and `min_allocator`
---
 libcxx/test/support/MinSequenceContainer.h |  2 +-
 libcxx/test/support/min_allocator.h        | 10 ++--------
 2 files changed, 3 insertions(+), 9 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..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::ptrdiff_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::ptrdiff_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