Add some reproducers for issues found developing the location-wrappers patch
[official-gcc.git] / gcc / testsuite / g++.dg / wrappers / alloc.C
blobe004470dbe9cff24c36377ca2271cb9b1929285f
1 // { dg-do compile { target c++11 } }
3 template<typename _Default, typename _AlwaysVoid, template<typename...> class _Op, typename... _Args>
4 struct __detector
6   using type = _Op<_Args...>;
7 };
8 template<typename _Default, template<typename...> class _Op, typename... _Args>
9 using __detected_or = __detector<_Default, void, _Op, _Args...>;
10 template<typename _Default, template<typename...> class _Op, typename... _Args>
11 using __detected_or_t = typename __detected_or<_Default, _Op, _Args...>::type;
12 template<typename _Alloc>
13 struct allocator_traits {
14   template<typename _Tp>
15   using __pointer = typename _Tp::pointer;
16   using pointer = __detected_or_t<typename _Alloc::value_type*, __pointer, _Alloc>;
18 template<typename _Storage_policy>
19 struct _Pointer_adapter {
20   typedef typename _Storage_policy::element_type element_type;
21   typedef element_type& reference;
23 template<typename _Tp>
24 inline _Tp* addressof(_Tp& __r); // { dg-warning "used but never defined" }
25 template<typename _Alloc>
26 struct __allocated_ptr {
27   __allocated_ptr()
28   {
29     using pointer = typename allocator_traits<_Alloc>::pointer;
30     typename _Pointer_adapter<pointer>::reference __r = *(int*)0;
31     addressof(__r);
32   }
34 template<typename _Tp>
35 struct _Std_pointer_impl {
36   typedef _Tp element_type;
38 template<typename Tp>
39 struct CustomPointerAlloc {
40   typedef Tp value_type;
41   typedef _Pointer_adapter<_Std_pointer_impl<Tp>> pointer;
43 __allocated_ptr<CustomPointerAlloc<int>> __guard_ptr;