[libcxx-commits] [libcxx] [libc++][test] Fix invalid low-level const conversion in limited_allocator (PR #118189)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 9 08:47:54 PST 2024


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

>From 3e55daf4023d9f3c13deab99b87e58b8828860ec Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Sat, 30 Nov 2024 21:20:59 -0500
Subject: [PATCH 1/2] Fix invalid low-level const conversion

---
 libcxx/test/support/test_allocator.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/support/test_allocator.h b/libcxx/test/support/test_allocator.h
index cf6952fcd788e6..b01345f8f7df6b 100644
--- a/libcxx/test/support/test_allocator.h
+++ b/libcxx/test/support/test_allocator.h
@@ -477,7 +477,10 @@ class limited_allocator {
   TEST_CONSTEXPR_CXX20 pointer allocate(size_type n) { return handle_->template allocate<T>(n); }
   TEST_CONSTEXPR_CXX20 void deallocate(pointer p, size_type n) { handle_->template deallocate<T>(p, n); }
   TEST_CONSTEXPR size_type max_size() const { return N; }
-  TEST_CONSTEXPR BuffT* getHandle() const { return handle_.get(); }
+
+  // In C++11, constexpr non-static member functions are implicitly const, but this is no longer the case since C++14.
+  TEST_CONSTEXPR_CXX14 BuffT* getHandle() { return handle_.get(); }
+  TEST_CONSTEXPR const BuffT* getHandle() const { return handle_.get(); }
 };
 
 template <class T, class U, std::size_t N>

>From a51a2db00c0684a4aaa74bd583a92a75144583e5 Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Fri, 6 Dec 2024 09:16:50 -0500
Subject: [PATCH 2/2] Provide only a const version and run required
 clang-format

---
 libcxx/test/support/test_allocator.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libcxx/test/support/test_allocator.h b/libcxx/test/support/test_allocator.h
index b01345f8f7df6b..f8b622d7f95209 100644
--- a/libcxx/test/support/test_allocator.h
+++ b/libcxx/test/support/test_allocator.h
@@ -477,9 +477,6 @@ class limited_allocator {
   TEST_CONSTEXPR_CXX20 pointer allocate(size_type n) { return handle_->template allocate<T>(n); }
   TEST_CONSTEXPR_CXX20 void deallocate(pointer p, size_type n) { handle_->template deallocate<T>(p, n); }
   TEST_CONSTEXPR size_type max_size() const { return N; }
-
-  // In C++11, constexpr non-static member functions are implicitly const, but this is no longer the case since C++14.
-  TEST_CONSTEXPR_CXX14 BuffT* getHandle() { return handle_.get(); }
   TEST_CONSTEXPR const BuffT* getHandle() const { return handle_.get(); }
 };
 



More information about the libcxx-commits mailing list