| 1 | // { dg-do run { target c++11 } } |
| 2 | #include <regex> |
| 3 | #include <testsuite_hooks.h> |
| 4 | #include <testsuite_allocator.h> |
| 5 | |
| 6 | template<typename T> |
| 7 | struct Alloc |
| 8 | { |
| 9 | using value_type = T; |
| 10 | explicit Alloc(int) { } |
| 11 | template<typename U> Alloc(const Alloc&) { } |
| 12 | |
| 13 | T* allocate(std::size_t n) |
| 14 | { return std::allocator<T>().allocate(n); } |
| 15 | void deallocate(T* ptr, std::size_t n) |
| 16 | { std::allocator<T>().deallocate(ptr, n); } |
| 17 | |
| 18 | bool operator==(const Alloc&) const { return true; } |
| 19 | bool operator!=(const Alloc&) const { return false; } |
| 20 | }; |
| 21 | |
| 22 | void |
| 23 | test_non_default_constructible() |
| 24 | { |
| 25 | using sub_match = std::sub_match<const char*>; |
| 26 | using alloc_type = Alloc<sub_match>; |
| 27 | using match_results = std::match_results<const char*, alloc_type>; |
| 28 | match_results res(alloc_type(1)); |
| 29 | |
| 30 | std::regex_match("x", res, std::regex(".")); // PR libstdc++/107376 |
| 31 | } |
| 32 | |
| 33 | template<typename T> |
| 34 | struct PropAlloc |
| 35 | { |
| 36 | int id; |
| 37 | |
| 38 | using value_type = T; |
| 39 | explicit PropAlloc(int id) : id(id) { } |
| 40 | template<typename U> PropAlloc(const PropAlloc& a) : id(a.id) { } |
| 41 | |
| 42 | using propagate_on_container_move_assignment = std::true_type; |
| 43 | using propagate_on_container_copy_assignment = std::true_type; |
| 44 | |
| 45 | PropAlloc select_on_container_copy_construction() const |
| 46 | { return PropAlloc(0); } |
| 47 | |
| 48 | T* allocate(std::size_t n) |
| 49 | { return std::allocator<T>().allocate(n); } |
| 50 | void deallocate(T* ptr, std::size_t n) |
| 51 | { std::allocator<T>().deallocate(ptr, n); } |
| 52 | |
| 53 | bool operator==(const PropAlloc& a) const { return id == a.id; } |
| 54 | bool operator!=(const PropAlloc& a) const { return id != a.id; } |
| 55 | }; |
| 56 | |
| 57 | void |
| 58 | test_propagation() |
| 59 | { |
| 60 | using sub_match = std::sub_match<const char*>; |
| 61 | using alloc_type = PropAlloc<sub_match>; |
| 62 | using match_results = std::match_results<const char*, alloc_type>; |
| 63 | alloc_type alloc(107376); |
| 64 | match_results res(alloc); |
| 65 | |
| 66 | std::regex re("..", std::regex_constants::__polynomial); |
| 67 | std::regex_match("xx", res, re); |
| 68 | |
| 69 | VERIFY( res.get_allocator() == alloc ); |
| 70 | } |
| 71 | |
| 72 | int main() |
| 73 | { |
| 74 | test_non_default_constructible(); |
| 75 | test_propagation(); |
| 76 | } |