... by accepting `std::size_t` instead of `int` in `allocate` and `deallocate` functions.
Drive-by: To conform to the allocator requirements, the `Allocator` types in these tests need to have (1) converting constructors and (2) cross-specialization `==` that returns `true` at least for copies of the same allocator.
Differential Revision: https://reviews.llvm.org/D141334
// <vector>
+#include <cstddef>
#include <vector>
#include "test_macros.h"
using value_type = T;
MyAlloc() = default;
template<class U> MyAlloc(const MyAlloc<U>&) {}
- T *allocate(int n) { return std::allocator<T>().allocate(n); }
- void deallocate(T *p, int n) { return std::allocator<T>().deallocate(p, n); }
+ T *allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
+ void deallocate(T *p, std::size_t n) { return std::allocator<T>().deallocate(p, n); }
};
int main(int, char**)
// (bug report: https://llvm.org/PR58392)
// Check that vector<bool> constructors don't leak memory when an operation inside the constructor throws an exception
+#include <cstddef>
#include <type_traits>
#include <vector>
throw 0;
}
- T* allocate(int n) { return std::allocator<T>().allocate(n); }
- void deallocate(T* ptr, int n) { std::allocator<T>().deallocate(ptr, n); }
+ T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
+ void deallocate(T* ptr, std::size_t n) { std::allocator<T>().deallocate(ptr, n); }
- friend bool operator==(const Allocator&, const Allocator&) { return false; }
+ template <class U>
+ friend bool operator==(const Allocator&, const Allocator<U>&) { return true; }
};
template <class IterCat>
// (bug report: https://llvm.org/PR58392)
// Check that vector constructors don't leak memory when an operation inside the constructor throws an exception
+#include <cstddef>
#include <type_traits>
#include <vector>
using value_type = T;
using is_always_equal = std::false_type;
+ template <class U>
+ Allocator(const Allocator<U>&) {}
+
Allocator(bool should_throw = true) {
if (should_throw)
throw 0;
}
- T* allocate(int n) { return std::allocator<T>().allocate(n); }
- void deallocate(T* ptr, int n) { std::allocator<T>().deallocate(ptr, n); }
+ T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
+ void deallocate(T* ptr, std::size_t n) { std::allocator<T>().deallocate(ptr, n); }
- friend bool operator==(const Allocator&, const Allocator&) { return false; }
+ template <class U>
+ friend bool operator==(const Allocator&, const Allocator<U>&) { return true; }
};
struct ThrowingT {