Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

Making it meet the requirements for allocator since C++11. Fixes #113609.

This PR doesn't make it meet the C++03 allocator requirements, because that would make the type too verbose and libc++ has backported many C++11 features to the C++03 mode.

Drive-by: Removes the TEST_CONSTEXPR_CXX14 on allocate/dealocate which is never in effect (and causes IFNDR-ness before C++23), since these functions modify the namespace-scoped variable allocated_.

Making it meet the requirements for allocator since C++11.

This PR doesn't make it meet the C++03 allocator requirements, because that would make the type too verbose and libc++ has backported many C++11 features to the C++03 mode.

Drive-by: Removes the `TEST_CONSTEXPR_CXX14` on `allocate`/`dealocate` which is never in effect (and causes IFNDR-ness before C++23), since these functions modify the namespace-scoped variable `allocated_`.
@frederick-vs-ja frederick-vs-ja added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite labels Oct 25, 2024
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner October 25, 2024 02:57
@llvmbot
Copy link
Member

llvmbot commented Oct 25, 2024

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

Making it meet the requirements for allocator since C++11. Fixes #113609.

This PR doesn't make it meet the C++03 allocator requirements, because that would make the type too verbose and libc++ has backported many C++11 features to the C++03 mode.

Drive-by: Removes the TEST_CONSTEXPR_CXX14 on allocate/dealocate which is never in effect (and causes IFNDR-ness before C++23), since these functions modify the namespace-scoped variable allocated_.


Full diff: https://github.com/llvm/llvm-project/pull/113638.diff

1 Files Affected:

  • (modified) libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp (+19-2)
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
index 1203b2f3ec18f9..00f9e2b8467837 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
@@ -34,15 +34,32 @@ struct test_alloc {
     typedef test_alloc<U, Sz> other;
   };
 
-  TEST_CONSTEXPR_CXX14 pointer allocate(size_type n, const void* = nullptr) {
+  TEST_CONSTEXPR test_alloc() TEST_NOEXCEPT {}
+
+  template <class U>
+  TEST_CONSTEXPR test_alloc(const test_alloc<U, Sz>&) TEST_NOEXCEPT {}
+
+  pointer allocate(size_type n, const void* = nullptr) {
     allocated_ += n;
     return std::allocator<value_type>().allocate(n);
   }
 
-  TEST_CONSTEXPR_CXX14 void deallocate(pointer p, size_type s) {
+  void deallocate(pointer p, size_type s) {
     allocated_ -= s;
     std::allocator<value_type>().deallocate(p, s);
   }
+
+  template <class U>
+  friend TEST_CONSTEXPR bool operator==(const test_alloc&, const test_alloc<U, Sz>&) TEST_NOEXCEPT {
+    return true;
+  }
+
+#if TEST_STD_VER < 20
+  template <class U>
+  friend TEST_CONSTEXPR bool operator!=(const test_alloc&, const test_alloc<U, Sz>&) TEST_NOEXCEPT {
+    return false;
+  }
+#endif
 };
 
 template <class Sz>

@frederick-vs-ja frederick-vs-ja merged commit f71ea0e into llvm:main Oct 29, 2024
65 checks passed
@frederick-vs-ja frederick-vs-ja deleted the cxx11-complete-deallocate_size-test_alloc branch October 29, 2024 23:16
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…vm#113638)

Making it meet the requirements for allocator since C++11. Fixes
llvm#113609.

This PR doesn't make it meet the C++03 allocator requirements, because
that would make the type too verbose and libc++ has backported many
C++11 features to the C++03 mode.

Drive-by: Removes the `TEST_CONSTEXPR_CXX14` on `allocate`/`dealocate`
which is never in effect (and causes IFNDR-ness before C++23), since
these functions modify the namespace-scoped variable `allocated_`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc++][test] Non-rebindable test_alloc in string.capacity/deallocate_size.pass.cpp

3 participants