Merge from branches/gcc-4_8-branch up to rev 207411.
[official-gcc.git] / gcc-4_8-branch / gcc / testsuite / g++.dg / torture / pr56029.C
blobca4a82a00604d1e714f16c42c2db0194b77e19a0
1 // PR tree-optimization/56029
2 // { dg-do compile }
4 template <class T>
5 struct DefaultDeleter
7   void operator () (T * ptr) { delete ptr; }
8 };
9 template <class T, class D>
10 struct scoped_ptr_impl
12   scoped_ptr_impl (T * p):data_ (p) {}
13   template <typename U, typename V>
14   scoped_ptr_impl (scoped_ptr_impl <U, V> *other):data_ (other->release (), get_deleter ()) {}
15   ~scoped_ptr_impl () { static_cast <D> (data_) (data_.ptr); }
16   void reset (T * p) { data_.ptr = p; }
17   D get_deleter () {}
18   T *release () { data_.ptr = __null; }
19   struct Data
20   : D
21   {
22     Data (T *) : ptr () {}
23     Data (T *, D) : D (), ptr () {}
24     T *ptr;
25   };
26   Data data_;
28 template <class T, class D = DefaultDeleter <T> >
29 struct scoped_ptr
31   struct RValue
32   {
33     RValue (scoped_ptr * object):object (object) {}
34     scoped_ptr *object;
35   };
36   scoped_ptr Pass () { return scoped_ptr ((this)); }
37   typedef T element_type;
38   typedef D deleter_type;
39   scoped_ptr () : impl_ (__null) {}
40   scoped_ptr (RValue rvalue) : impl_ (&rvalue.object->impl_) {}
41   void reset (element_type * p) { impl_.reset (p); }
42   scoped_ptr_impl <element_type, deleter_type> impl_;
44 template <typename>
45 struct Callback;
46 struct ClientSocketFactory;
47 struct DatagramClientSocket;
48 struct DnsSocketPool
50   scoped_ptr <DatagramClientSocket> CreateConnectedSocket ();
51   ClientSocketFactory *socket_factory_;
53 int RandInt (int, int);
54 struct BindStateBase {};
55 struct CallbackBase
57   CallbackBase (BindStateBase *);
58   ~CallbackBase ();
60 template <typename, typename, typename>
61 struct BindState;
62 template <typename R, typename A1, typename A2>
63 struct Callback <R (A1, A2)> : CallbackBase
65   template <typename Runnable, typename BindRunType, typename BoundArgsType>
66   Callback (BindState <Runnable, BindRunType, BoundArgsType> *bind_state) : CallbackBase (bind_state) {}
68 typedef Callback <int (int, int)>
69 RandIntCallback;
70 struct ClientSocketFactory
72   virtual DatagramClientSocket *CreateDatagramClientSocket (RandIntCallback) = 0;
74 template <typename>
75 struct RunnableAdapter;
76 template <typename R, typename A1, typename A2>
77 struct RunnableAdapter <R (*) (A1, A2)>
79   typedef R (RunType) (A1, A2);
81 template <typename T>
82 struct FunctorTraits
84   typedef RunnableAdapter <T> RunnableType;
85   typedef typename RunnableType::RunType RunType;
87 template <typename T>
88 typename FunctorTraits <T>::RunnableType MakeRunnable (T)
91 template <int, typename, typename>
92 struct Invoker;
93 template <typename StorageType, typename R, typename X1, typename X2>
94 struct Invoker <0, StorageType, R (X1, X2)>
96   typedef R (UnboundRunType) (X1, X2);
98 template <typename Runnable, typename RunType>
99 struct BindState <Runnable, RunType, void ()> : BindStateBase
101   typedef Runnable RunnableType;
102   typedef Invoker <0, BindState, RunType> InvokerType;
103   typedef typename InvokerType::UnboundRunType UnboundRunType;
104   BindState (Runnable):runnable_ () {}
105   RunnableType runnable_;
107 template <typename Functor>
108 Callback <typename BindState <typename FunctorTraits <Functor>::RunnableType, typename FunctorTraits <Functor>::RunType, void ()>::UnboundRunType>
109 Bind (Functor functor)
111   typedef typename FunctorTraits <Functor>::RunnableType RunnableType;
112   typedef typename FunctorTraits <Functor>::RunType RunType;
113   typedef BindState <RunnableType, RunType, void ()> BindState;
114   Callback <typename BindState::UnboundRunType> (new BindState (MakeRunnable (functor)));
116 struct DatagramClientSocket
118   virtual ~ DatagramClientSocket ();
120 scoped_ptr <DatagramClientSocket>
121 DnsSocketPool::CreateConnectedSocket ()
123   scoped_ptr <DatagramClientSocket> socket;
124   socket.reset (socket_factory_->CreateDatagramClientSocket (Bind (RandInt)));
125   socket.Pass ();