[libcxx-commits] [libcxx] [libcxx][string] Test: default constructed allocators can be unequal (PR #195839)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 13 11:58:08 PDT 2026
================
@@ -515,4 +515,40 @@ struct SocccAllocator {
using propagate_on_container_swap = std::false_type;
};
+// Track how many times the allocator was default-constructed
+//
+
+template <class T>
+class ControlledDefaultConstructorAllocator : public std::allocator<T> {
+public:
+ template <class U>
+ struct rebind {
+ typedef ControlledDefaultConstructorAllocator<U> other;
+ };
+
+ ControlledDefaultConstructorAllocator() TEST_NOEXCEPT { default_constructed_tag_ = next_default_constructed_tag_++; }
+ bool is_base() const TEST_NOEXCEPT { return default_constructed_tag_ == base_default_constructed_tag_; }
+
+ static void reset_to_base() { next_default_constructed_tag_ = base_default_constructed_tag_; }
----------------
ldionne wrote:
```suggestion
static void set_default_value(int value) { next_value = value; }
```
That way in the tests you can do:
```
A::set_default_value(42);
basic_string<char, A> s(first, last);
assert(s.get_allocator().value == 42);
```
This removes the need for `is_base` and for understanding that there's a special "base" value, since all the knowledge is now local to the callsite and obvious from the names used.
https://github.com/llvm/llvm-project/pull/195839
More information about the libcxx-commits
mailing list