2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr56029.C
blob72ad59b4354e139d9e439ef1fdf03ff0d83e1934
1 // PR tree-optimization/56029
2 // { dg-do compile }
3 // { dg-additional-options "-Wno-return-type" }
5 template <class T>
6 struct DefaultDeleter
8   void operator () (T * ptr) { delete ptr; }
9 };
10 template <class T, class D>
11 struct scoped_ptr_impl
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_;
29 template <class T, class D = DefaultDeleter <T> >
30 struct scoped_ptr
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_;
45 template <typename>
46 struct Callback;
47 struct ClientSocketFactory;
48 struct DatagramClientSocket;
49 struct DnsSocketPool
51   scoped_ptr <DatagramClientSocket> CreateConnectedSocket ();
52   ClientSocketFactory *socket_factory_;
54 int RandInt (int, int);
55 struct BindStateBase {};
56 struct CallbackBase
58   CallbackBase (BindStateBase *);
59   ~CallbackBase ();
61 template <typename, typename, typename>
62 struct BindState;
63 template <typename R, typename A1, typename A2>
64 struct Callback <R (A1, A2)> : CallbackBase
66   template <typename Runnable, typename BindRunType, typename BoundArgsType>
67   Callback (BindState <Runnable, BindRunType, BoundArgsType> *bind_state) : CallbackBase (bind_state) {}
69 typedef Callback <int (int, int)>
70 RandIntCallback;
71 struct ClientSocketFactory
73   virtual DatagramClientSocket *CreateDatagramClientSocket (RandIntCallback) = 0;
75 template <typename>
76 struct RunnableAdapter;
77 template <typename R, typename A1, typename A2>
78 struct RunnableAdapter <R (*) (A1, A2)>
80   typedef R (RunType) (A1, A2);
82 template <typename T>
83 struct FunctorTraits
85   typedef RunnableAdapter <T> RunnableType;
86   typedef typename RunnableType::RunType RunType;
88 template <typename T>
89 typename FunctorTraits <T>::RunnableType MakeRunnable (T)
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)>
97   typedef R (UnboundRunType) (X1, X2);
99 template <typename Runnable, typename RunType>
100 struct BindState <Runnable, RunType, void ()> : BindStateBase
102   typedef Runnable RunnableType;
103   typedef Invoker <0, BindState, RunType> InvokerType;
104   typedef typename InvokerType::UnboundRunType UnboundRunType;
105   BindState (Runnable):runnable_ () {}
106   RunnableType runnable_;
108 template <typename Functor>
109 Callback <typename BindState <typename FunctorTraits <Functor>::RunnableType, typename FunctorTraits <Functor>::RunType, void ()>::UnboundRunType>
110 Bind (Functor functor)
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)));
117 struct DatagramClientSocket
119   virtual ~ DatagramClientSocket ();
121 scoped_ptr <DatagramClientSocket>
122 DnsSocketPool::CreateConnectedSocket ()
124   scoped_ptr <DatagramClientSocket> socket;
125   socket.reset (socket_factory_->CreateDatagramClientSocket (Bind (RandInt)));
126   socket.Pass ();