[libcxx-commits] [libcxx] [libc++][test] Fix construction and comparison for testing allocators (PR #212702)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 29 05:04:49 PDT 2026
================
@@ -195,8 +195,14 @@ class test_allocator {
++stats_->destroy_count;
p->~T();
}
- TEST_CONSTEXPR friend bool operator==(const test_allocator& x, const test_allocator& y) { return x.data_ == y.data_; }
- TEST_CONSTEXPR friend bool operator!=(const test_allocator& x, const test_allocator& y) { return !(x == y); }
+ template <class U>
+ TEST_CONSTEXPR friend bool operator==(const test_allocator& x, const test_allocator<U>& y) {
+ return x.data_ == static_cast<const test_allocator&>(y).data_;
----------------
frederick-vs-ja wrote:
> I suppose we won't be supporting GCC15 for much longer. Maybe add a TODO to remove the workaround?
I'm not sure whether the we want to remove the workaround. The original strategy I used was
```C++
const test_allocator& y2 = y;
return x.data_ == y2.data_;
```
which was arguably more verbose.
If we cast to `test_allocator` or directly compare `data_` via `get_data()`, then `stats_->construct_count` or `stats_->converted` would have different values.
https://github.com/llvm/llvm-project/pull/212702
More information about the libcxx-commits
mailing list