[libcxx-commits] [libcxx] d65e66a - [libcxx][test] fix allocator in allocator_propagation test

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 4 15:34:49 PST 2023


Author: Casey Carter
Date: 2023-01-04T15:33:42-08:00
New Revision: d65e66abb3bd4535e1900c0c7901c0f6254acf34

URL: https://github.com/llvm/llvm-project/commit/d65e66abb3bd4535e1900c0c7901c0f6254acf34
DIFF: https://github.com/llvm/llvm-project/commit/d65e66abb3bd4535e1900c0c7901c0f6254acf34.diff

LOG: [libcxx][test] fix allocator in allocator_propagation test

The converting constructor is ill-formed, and `==` is missing. (I didn't implement `!=` since the test is C++20-and-later only; I'll let the compiler do it for us.)

Drive-by: change 4-space indent on line 27 to 2-space indent to be consistent with the rest of the test.

Differential Revision: https://reviews.llvm.org/D131079

Added: 
    

Modified: 
    libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/allocator_propagation.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/allocator_propagation.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/allocator_propagation.pass.cpp
index 9293b854db03a..a03101d770942 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/allocator_propagation.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/allocator_propagation.pass.cpp
@@ -24,10 +24,10 @@ class soccc_allocator {
   using value_type = T;
 
   constexpr explicit soccc_allocator(int* soccc_count_, int self_coccc_count_ = 0)
-      : soccc_count(soccc_count_), self_soccc_count(self_coccc_count_) {}
+    : soccc_count(soccc_count_), self_soccc_count(self_coccc_count_) {}
 
   template <class U>
-  constexpr soccc_allocator(const soccc_allocator<U>& a) : soccc_count(a.soccc_count) {}
+  constexpr soccc_allocator(const soccc_allocator<U>& a) : soccc_count(a.get_soccc()) {}
 
   constexpr T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
   constexpr void deallocate(T* p, std::size_t s) { std::allocator<T>().deallocate(p, s); }
@@ -37,12 +37,17 @@ class soccc_allocator {
     return soccc_allocator(soccc_count, self_soccc_count + 1);
   }
 
-  constexpr auto get_soccc() { return soccc_count; }
-  constexpr auto get_self_soccc() { return self_soccc_count; }
+  constexpr auto get_soccc() const { return soccc_count; }
+  constexpr auto get_self_soccc() const { return self_soccc_count; }
 
   typedef std::true_type propagate_on_container_copy_assignment;
   typedef std::true_type propagate_on_container_move_assignment;
   typedef std::true_type propagate_on_container_swap;
+
+  template <class U>
+  constexpr bool operator==(const soccc_allocator<U>& that) const {
+    return soccc_count == that.get_soccc();
+  }
 };
 
 template <class CharT>


        


More information about the libcxx-commits mailing list