| 1 |
// { dg-do compile } |
| 2 |
// { dg-additional-options "-fnon-call-exceptions -fno-inline-functions-called-once -fno-tree-sra --param early-inlining-insns=1" } |
| 3 |
template <typename, typename> struct __replace_first_arg; |
| 4 |
template <template <typename> class _Template, typename _Up, typename _Tp, |
| 5 |
typename... _Types> |
| 6 |
struct __replace_first_arg<_Template<_Tp, _Types...>, _Up> { |
| 7 |
using type = _Template<_Up>; |
| 8 |
}; |
| 9 |
template <class> class min_pointer; |
| 10 |
struct pointer_traits { |
| 11 |
template <typename _Up> |
| 12 |
using rebind = typename __replace_first_arg<min_pointer<int>, _Up>::type; |
| 13 |
}; |
| 14 |
template <typename, typename _Tp> |
| 15 |
using __ptr_rebind = pointer_traits::rebind<_Tp>; |
| 16 |
template <typename _Alloc> struct allocator_traits { |
| 17 |
template <typename _Tp> |
| 18 |
static auto construct(_Alloc, _Tp) noexcept -> decltype(0); |
| 19 |
}; |
| 20 |
template <typename _ForwardIterator, typename _Allocator> |
| 21 |
void _Destroy(_ForwardIterator __last, _Allocator) { |
| 22 |
_ForwardIterator __first; |
| 23 |
for (; __first != __last;) |
| 24 |
; |
| 25 |
} |
| 26 |
template <typename _ForwardIterator, typename _Allocator> |
| 27 |
void __uninitialized_default_a(_ForwardIterator __last, _Allocator __alloc) { |
| 28 |
_ForwardIterator __first; |
| 29 |
try { |
| 30 |
for (; __first != __last;) |
| 31 |
allocator_traits<_Allocator>::construct(__alloc, 0); |
| 32 |
} catch (...) { |
| 33 |
_Destroy(__first, __alloc); |
| 34 |
} |
| 35 |
} |
| 36 |
template <typename _Ptr> struct _Deque_iterator { |
| 37 |
typedef __ptr_rebind<_Ptr, __ptr_rebind<_Ptr, int>> _Map_pointer; |
| 38 |
}; |
| 39 |
template <typename _Alloc> class _Deque_base { |
| 40 |
protected: |
| 41 |
typedef _Alloc _Tp_alloc_type; |
| 42 |
typedef _Deque_iterator<typename _Tp_alloc_type ::pointer> iterator; |
| 43 |
_Deque_base(_Alloc, long); |
| 44 |
typedef typename iterator::_Map_pointer _Map_pointer; |
| 45 |
_Tp_alloc_type _M_get_Tp_allocator(); |
| 46 |
}; |
| 47 |
template <typename _Alloc> class deque : _Deque_base<_Alloc> { |
| 48 |
typedef _Deque_base<_Alloc> _Base; |
| 49 |
typedef typename _Base::_Map_pointer _Map_pointer; |
| 50 |
typedef typename _Base::iterator iterator; |
| 51 |
using _Base::_M_get_Tp_allocator; |
| 52 |
|
| 53 |
public: |
| 54 |
deque(int, _Alloc __a) : _Base(__a, 0) { |
| 55 |
_Map_pointer __cur; |
| 56 |
try { |
| 57 |
__uninitialized_default_a(__cur, _M_get_Tp_allocator()); |
| 58 |
} catch (...) { |
| 59 |
} |
| 60 |
_M_destroy_data(begin(), end(), 0); |
| 61 |
} |
| 62 |
iterator begin(); |
| 63 |
iterator end(); |
| 64 |
template <typename _Alloc1> |
| 65 |
void _M_destroy_data(iterator, iterator, _Alloc1) { |
| 66 |
for (_Map_pointer __node;;) |
| 67 |
_Destroy(__node, _M_get_Tp_allocator()); |
| 68 |
} |
| 69 |
}; |
| 70 |
template <class T> class min_pointer { |
| 71 |
T ptr_; |
| 72 |
friend bool operator==(min_pointer x, min_pointer y) { |
| 73 |
return x.ptr_ == y.ptr_; |
| 74 |
} |
| 75 |
friend bool operator!=(min_pointer x, min_pointer y) { return x == y; } |
| 76 |
}; |
| 77 |
template <class> class min_allocator { |
| 78 |
public: |
| 79 |
typedef int pointer; |
| 80 |
}; |
| 81 |
int foo() { |
| 82 |
int n; |
| 83 |
min_allocator<int> alloc; |
| 84 |
deque<min_allocator<int>>(n, alloc); |
| 85 |
return 1; |
| 86 |
} |
| 87 |
|