[libcxx-commits] [libcxx] [libc++] Fix allocate_at_least test that assumes the size_type of the allocator (PR #131682)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 17 19:47:06 PDT 2025


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/131682

>From 6e2568b7efa53b3f64007d4a88f7bc129677fadc Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 17 Mar 2025 18:01:05 -0400
Subject: [PATCH 1/2] [libc++] Fix allocate_at_least test that assumes the
 size_type of the allocator

If the size_type of the allocator is not the same as std::size_t, this
test would fail.
---
 .../allocate_at_least.pass.cpp                         | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp
index 88ae44c627584..ee899dcb3e66d 100644
--- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp
@@ -45,16 +45,18 @@ struct has_allocate_at_least {
 constexpr bool test() {
   { // check that std::allocate_at_least forwards to allocator::allocate if no allocate_at_least exists
     no_allocate_at_least<int> alloc;
-    std::same_as<std::allocation_result<int*>> decltype(auto) ret =
-        std::allocator_traits<decltype(alloc)>::allocate_at_least(alloc, 1);
+    using AllocTraits = std::allocator_traits<decltype(alloc)>;
+    std::same_as<std::allocation_result<int*>, AllocTraits::size_type> decltype(auto) ret =
+        AllocTraits::allocate_at_least(alloc, 1);
     assert(ret.count == 1);
     assert(ret.ptr == &alloc.t);
   }
 
   { // check that std::allocate_at_least forwards to allocator::allocate_at_least if allocate_at_least exists
     has_allocate_at_least<int> alloc;
-    std::same_as<std::allocation_result<int*>> decltype(auto) ret =
-        std::allocator_traits<decltype(alloc)>::allocate_at_least(alloc, 1);
+    using AllocTraits = std::allocator_traits<decltype(alloc)>;
+    std::same_as<std::allocation_result<int*>, AllocTraits::size_type> decltype(auto) ret =
+        AllocTraits::allocate_at_least(alloc, 1);
     assert(ret.count == 2);
     assert(ret.ptr == &alloc.t2);
   }

>From cd454fd8fca7adbc7af8fb74d401be6c667d4f45 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 17 Mar 2025 22:46:57 -0400
Subject: [PATCH 2/2] Fix template param

---
 .../allocator.traits.members/allocate_at_least.pass.cpp       | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp
index ee899dcb3e66d..8a9425a2ec9c2 100644
--- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_at_least.pass.cpp
@@ -46,7 +46,7 @@ constexpr bool test() {
   { // check that std::allocate_at_least forwards to allocator::allocate if no allocate_at_least exists
     no_allocate_at_least<int> alloc;
     using AllocTraits = std::allocator_traits<decltype(alloc)>;
-    std::same_as<std::allocation_result<int*>, AllocTraits::size_type> decltype(auto) ret =
+    std::same_as<std::allocation_result<int*, AllocTraits::size_type>> decltype(auto) ret =
         AllocTraits::allocate_at_least(alloc, 1);
     assert(ret.count == 1);
     assert(ret.ptr == &alloc.t);
@@ -55,7 +55,7 @@ constexpr bool test() {
   { // check that std::allocate_at_least forwards to allocator::allocate_at_least if allocate_at_least exists
     has_allocate_at_least<int> alloc;
     using AllocTraits = std::allocator_traits<decltype(alloc)>;
-    std::same_as<std::allocation_result<int*>, AllocTraits::size_type> decltype(auto) ret =
+    std::same_as<std::allocation_result<int*, AllocTraits::size_type>> decltype(auto) ret =
         AllocTraits::allocate_at_least(alloc, 1);
     assert(ret.count == 2);
     assert(ret.ptr == &alloc.t2);



More information about the libcxx-commits mailing list