| 1 |
// PR tree-optimization/56029 |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-additional-options "-Wno-return-type" } |
| 4 |
|
| 5 |
template <class T> |
| 6 |
struct DefaultDeleter |
| 7 |
{ |
| 8 |
void operator () (T * ptr) { delete ptr; } |
| 9 |
}; |
| 10 |
template <class T, class D> |
| 11 |
struct scoped_ptr_impl |
| 12 |
{ |
| 13 |
scoped_ptr_impl (T * p):data_ (p) {} |
| 14 |
template <typename U, typename V> |
| 15 |
scoped_ptr_impl (scoped_ptr_impl <U, V> *other):data_ (other->release (), get_deleter ()) {} |
| 16 |
~scoped_ptr_impl () { static_cast <D> (data_) (data_.ptr); } |
| 17 |
void reset (T * p) { data_.ptr = p; } |
| 18 |
D get_deleter () {} |
| 19 |
T *release () { data_.ptr = __null; } |
| 20 |
struct Data |
| 21 |
: D |
| 22 |
{ |
| 23 |
Data (T *) : ptr () {} |
| 24 |
Data (T *, D) : D (), ptr () {} |
| 25 |
T *ptr; |
| 26 |
}; |
| 27 |
Data data_; |
| 28 |
}; |
| 29 |
template <class T, class D = DefaultDeleter <T> > |
| 30 |
struct scoped_ptr |
| 31 |
{ |
| 32 |
struct RValue |
| 33 |
{ |
| 34 |
RValue (scoped_ptr * object):object (object) {} |
| 35 |
scoped_ptr *object; |
| 36 |
}; |
| 37 |
scoped_ptr Pass () { return scoped_ptr ((this)); } |
| 38 |
typedef T element_type; |
| 39 |
typedef D deleter_type; |
| 40 |
scoped_ptr () : impl_ (__null) {} |
| 41 |
scoped_ptr (RValue rvalue) : impl_ (&rvalue.object->impl_) {} |
| 42 |
void reset (element_type * p) { impl_.reset (p); } |
| 43 |
scoped_ptr_impl <element_type, deleter_type> impl_; |
| 44 |
}; |
| 45 |
template <typename> |
| 46 |
struct Callback; |
| 47 |
struct ClientSocketFactory; |
| 48 |
struct DatagramClientSocket; |
| 49 |
struct DnsSocketPool |
| 50 |
{ |
| 51 |
scoped_ptr <DatagramClientSocket> CreateConnectedSocket (); |
| 52 |
ClientSocketFactory *socket_factory_; |
| 53 |
}; |
| 54 |
int RandInt (int, int); |
| 55 |
struct BindStateBase {}; |
| 56 |
struct CallbackBase |
| 57 |
{ |
| 58 |
CallbackBase (BindStateBase *); |
| 59 |
~CallbackBase (); |
| 60 |
}; |
| 61 |
template <typename, typename, typename> |
| 62 |
struct BindState; |
| 63 |
template <typename R, typename A1, typename A2> |
| 64 |
struct Callback <R (A1, A2)> : CallbackBase |
| 65 |
{ |
| 66 |
template <typename Runnable, typename BindRunType, typename BoundArgsType> |
| 67 |
Callback (BindState <Runnable, BindRunType, BoundArgsType> *bind_state) : CallbackBase (bind_state) {} |
| 68 |
}; |
| 69 |
typedef Callback <int (int, int)> |
| 70 |
RandIntCallback; |
| 71 |
struct ClientSocketFactory |
| 72 |
{ |
| 73 |
virtual DatagramClientSocket *CreateDatagramClientSocket (RandIntCallback) = 0; |
| 74 |
}; |
| 75 |
template <typename> |
| 76 |
struct RunnableAdapter; |
| 77 |
template <typename R, typename A1, typename A2> |
| 78 |
struct RunnableAdapter <R (*) (A1, A2)> |
| 79 |
{ |
| 80 |
typedef R (RunType) (A1, A2); |
| 81 |
}; |
| 82 |
template <typename T> |
| 83 |
struct FunctorTraits |
| 84 |
{ |
| 85 |
typedef RunnableAdapter <T> RunnableType; |
| 86 |
typedef typename RunnableType::RunType RunType; |
| 87 |
}; |
| 88 |
template <typename T> |
| 89 |
typename FunctorTraits <T>::RunnableType MakeRunnable (T) |
| 90 |
{ |
| 91 |
} |
| 92 |
template <int, typename, typename> |
| 93 |
struct Invoker; |
| 94 |
template <typename StorageType, typename R, typename X1, typename X2> |
| 95 |
struct Invoker <0, StorageType, R (X1, X2)> |
| 96 |
{ |
| 97 |
typedef R (UnboundRunType) (X1, X2); |
| 98 |
}; |
| 99 |
template <typename Runnable, typename RunType> |
| 100 |
struct BindState <Runnable, RunType, void ()> : BindStateBase |
| 101 |
{ |
| 102 |
typedef Runnable RunnableType; |
| 103 |
typedef Invoker <0, BindState, RunType> InvokerType; |
| 104 |
typedef typename InvokerType::UnboundRunType UnboundRunType; |
| 105 |
BindState (Runnable):runnable_ () {} |
| 106 |
RunnableType runnable_; |
| 107 |
}; |
| 108 |
template <typename Functor> |
| 109 |
Callback <typename BindState <typename FunctorTraits <Functor>::RunnableType, typename FunctorTraits <Functor>::RunType, void ()>::UnboundRunType> |
| 110 |
Bind (Functor functor) |
| 111 |
{ |
| 112 |
typedef typename FunctorTraits <Functor>::RunnableType RunnableType; |
| 113 |
typedef typename FunctorTraits <Functor>::RunType RunType; |
| 114 |
typedef BindState <RunnableType, RunType, void ()> BindState; |
| 115 |
Callback <typename BindState::UnboundRunType> (new BindState (MakeRunnable (functor))); |
| 116 |
} |
| 117 |
struct DatagramClientSocket |
| 118 |
{ |
| 119 |
virtual ~ DatagramClientSocket (); |
| 120 |
}; |
| 121 |
scoped_ptr <DatagramClientSocket> |
| 122 |
DnsSocketPool::CreateConnectedSocket () |
| 123 |
{ |
| 124 |
scoped_ptr <DatagramClientSocket> socket; |
| 125 |
socket.reset (socket_factory_->CreateDatagramClientSocket (Bind (RandInt))); |
| 126 |
socket.Pass (); |
| 127 |
} |