| 1 | // { dg-do compile { target c++11 } } |
| 2 | #include <vector> |
| 3 | |
| 4 | // Custom allocator defined with std::allocator, but doesn't provide rebind. |
| 5 | template<typename T> struct Alloc : std::allocator<T> { }; |
| 6 | |
| 7 | std::vector<int, Alloc<int>> v; // { dg-error "here" "" { target c++17_down } } |
| 8 | |
| 9 | // Custom allocator that does provide rebind, but incorrectly. |
| 10 | template<typename T> struct Alloc2 |
| 11 | { |
| 12 | using value_type = T; |
| 13 | template<typename U> struct rebind { using other = Alloc<U>; }; // not Alloc2 |
| 14 | T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); } |
| 15 | void deallocate(T* p, std::size_t n) { std::allocator<T>().deallocate(p, n); } |
| 16 | }; |
| 17 | |
| 18 | std::vector<int, Alloc2<int>> v2; // { dg-error "here" } |
| 19 | |
| 20 | // { dg-error "static assertion failed: .*rebind_alloc" "" { target *-*-* } 0 } |