1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2008-2013 Free Software Foundation, Inc.
5 Contributed by Red Hat, originally written by Keith Seitz.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Please email any bugs, comments, and/or additions to this file to:
30 // A simple template with specializations
35 void do_something () { } // tclass<T>::do_something
39 void tclass
<char>::do_something () { } // tclass<char>::do_something
42 void tclass
<int>::do_something () { } // tclass<int>::do_something
45 void tclass
<long>::do_something () { } // tclass<long>::do_something
48 void tclass
<short>::do_something () { } // tclass<short>::do_something
50 // A simple template with multiple template parameters
51 template <class A
, class B
, class C
, class D
, class E
>
52 void flubber (void) // flubber
67 // Some contrived policies
71 static void function (void) { } // operation_1<T>::function
77 static void function (void) { } // operation_2<T>::function
83 static void function (void) { } // operation_3<T>::function
89 static void function (void) { } // operation_4<T>::function
92 // A policy-based class w/ and w/o default policy
93 template <class T
, class Policy
>
94 class policy
: public Policy
97 policy (T obj
) : obj_ (obj
) { } // policy<T, Policy>::policy
103 template <class T
, class Policy
= operation_1
<T
> >
104 class policyd
: public Policy
107 policyd (T obj
) : obj_ (obj
) { } // policyd<T, Policy>::policyd
108 ~policyd (void) { } // policyd<T, Policy>::~policyd
114 typedef policy
<int, operation_1
<void*> > policy1
;
115 typedef policy
<int, operation_2
<void*> > policy2
;
116 typedef policy
<int, operation_3
<void*> > policy3
;
117 typedef policy
<int, operation_4
<void*> > policy4
;
119 typedef policyd
<int> policyd1
;
120 typedef policyd
<long> policyd2
;
121 typedef policyd
<char> policyd3
;
122 typedef policyd
<base
> policyd4
;
123 typedef policyd
<tclass
<int> > policyd5
;
126 static fluff
*g_fluff
= new fluff ();
134 base (void) : foo_ (42) { } // base::base(void)
135 base (int foo
) : foo_ (foo
) { } // base::base(int)
136 ~base (void) { } // base::~base
138 // Some overloaded methods
139 int overload (void) const { return 0; } // base::overload(void) const
140 int overload (int i
) const { return 1; } // base::overload(int) const
141 int overload (short s
) const { return 2; } // base::overload(short) const
142 int overload (long l
) const { return 3; } // base::overload(long) const
143 int overload (char* a
) const { return 4; } // base::overload(char*) const
144 int overload (base
& b
) const { return 5; } // base::overload(base&) const
147 int operator+ (base
const& o
) const // base::operator+
148 { return foo_
+ o
.foo_
; }
150 base
operator++ (void) // base::operator++
151 { ++foo_
; return *this; }
153 base
operator+=(base
const& o
) // base::operator+=
154 { foo_
+= o
.foo_
; return *this; }
156 int operator- (base
const& o
) const // base::operator-
157 { return foo_
- o
.foo_
; }
159 base
operator-- (void) // base::operator--
160 { --foo_
; return *this; }
162 base
operator-= (base
const& o
) // base::operator-=
163 { foo_
-= o
.foo_
; return *this; }
165 int operator* (base
const& o
) const // base::operator*
166 { return foo_
* o
.foo_
; }
168 base
operator*= (base
const& o
) // base::operator*=
169 { foo_
*= o
.foo_
; return *this; }
171 int operator/ (base
const& o
) const // base::operator/
172 { return foo_
/ o
.foo_
; }
174 base
operator/= (base
const& o
) // base::operator/=
175 { foo_
/= o
.foo_
; return *this; }
177 int operator% (base
const& o
) const // base::operator%
178 { return foo_
% o
.foo_
; }
180 base
operator%= (base
const& o
) // base::operator%=
181 { foo_
%= o
.foo_
; return *this; }
183 bool operator< (base
const& o
) const // base::operator<
184 { return foo_
< o
.foo_
; }
186 bool operator<= (base
const& o
) const // base::operator<=
187 { return foo_
<= o
.foo_
; }
189 bool operator> (base
const& o
) const // base::operator>
190 { return foo_
> o
.foo_
; }
192 bool operator>= (base
const& o
) const // base::operator>=
193 { return foo_
>= o
.foo_
; }
195 bool operator!= (base
const& o
) const // base::operator!=
196 { return foo_
!= o
.foo_
; }
198 bool operator== (base
const& o
) const // base::operator==
199 { return foo_
== o
.foo_
; }
201 bool operator! (void) const // base::operator!
204 bool operator&& (base
const& o
) const // base::operator&&
205 { return foo_
&& o
.foo_
; }
207 bool operator|| (base
const& o
) const // base::operator||
208 { return foo_
|| o
.foo_
; }
210 int operator<< (int value
) const // base::operator<<
211 { return foo_
<< value
; }
213 base
operator<<= (int value
) // base::operator<<=
214 { foo_
<<= value
; return *this; }
216 int operator>> (int value
) const // base::operator>>
217 { return foo_
>> value
; }
219 base
operator>>= (int value
) // base::operator>>=
220 { foo_
>>= value
; return *this; }
222 int operator~ (void) const // base::operator~
225 int operator& (base
const& o
) const // base::operator&
226 { return foo_
& o
.foo_
; }
228 base
operator&= (base
const& o
) // base::operator&=
229 { foo_
&= o
.foo_
; return *this; }
231 int operator| (base
const& o
) const // base::operator|
232 { return foo_
| o
.foo_
; }
234 base
operator|= (base
const& o
) // base::operator|=
235 { foo_
|= o
.foo_
; return *this; }
237 int operator^ (base
const& o
) const // base::operator^
238 { return foo_
^ o
.foo_
; }
240 base
operator^= (base
const& o
) // base::operator^=
241 { foo_
^= o
.foo_
; return *this; }
243 base
operator= (base
const& o
) // base::operator=
244 { foo_
= o
.foo_
; return *this; }
246 void operator() (void) const // base::operator()
249 int operator[] (int idx
) const // base::operator[]
252 void* operator new (size_t size
) throw () // base::operator new
253 { return malloc (size
); }
255 void operator delete (void* ptr
) // base::operator delete
258 void* operator new[] (size_t size
) throw () // base::operator new[]
259 { return malloc (size
); }
261 void operator delete[] (void* ptr
) // base::operator delete[]
264 base
const* operator-> (void) const // base::opeartor->
267 int operator->* (base
const& b
) const // base::operator->*
268 { return foo_
* b
.foo_
; }
270 operator char* () const { return const_cast<char*> ("hello"); } // base::operator char*
271 operator int () const { return 21; } // base::operator int
272 operator fluff
* () const { return new fluff (); } // base::operator fluff*
273 operator fluff
** () const { return &g_fluff
; } // base::operator fluff**
276 class base1
: public virtual base
279 base1 (void) : foo_ (21) { } // base1::base1(void)
280 base1 (int a
) : foo_(a
) { } // base1::base1(int)
281 void a_function (void) const { } // base1::a_function
287 class base2
: public virtual base
290 base2 () : foo_ (3) { } // base2::base2
293 void a_function (void) const { } // base2::a_function
297 class derived
: public base1
, public base2
300 derived(void) : foo_ (4) { } // derived::derived
301 void a_function (void) const // derived::a_function
303 this->base1::a_function ();
304 this->base2::a_function ();
317 void m(t
) const volatile;
319 const int CV::i
= 42;
321 # define ATTRIBUTE_USED __attribute__((used))
323 # define ATTRIBUTE_USED
325 ATTRIBUTE_USED
void CV::m(CV::t
) {}
326 ATTRIBUTE_USED
void CV::m(CV::t
) const {}
327 ATTRIBUTE_USED
void CV::m(CV::t
) volatile {}
328 ATTRIBUTE_USED
void CV::m(CV::t
) const volatile {}
335 test_function (int argc
, char* argv
[]) // test_function
338 void (derived::*pfunc
) (void) const = &derived::a_function
;
341 base
a (1), b (3), c (8);
342 (void) a
.overload ();
343 (void) a
.overload (static_cast<int> (0));
344 (void) a
.overload (static_cast<short> (0));
345 (void) a
.overload (static_cast<long> (0));
346 (void) a
.overload (static_cast<char*> (0));
347 (void) a
.overload (a
);
385 derived
* f
= new derived ();
386 derived
* g
= new derived
[3];
392 tclass
<char> char_tclass
;
393 tclass
<int> int_tclass
;
394 tclass
<short> short_tclass
;
395 tclass
<long> long_tclass
;
396 tclass
<base
> base_tclass
;
397 char_tclass
.do_something ();
398 int_tclass
.do_something ();
399 short_tclass
.do_something ();
400 long_tclass
.do_something ();
401 base_tclass
.do_something ();
403 flubber
<int, int, int, int, int> ();
404 flubber
<int, int, int, int, short> ();
405 flubber
<int, int, int, int, long> ();
406 flubber
<int, int, int, int, char> ();
407 flubber
<int, int, int, short, int> ();
408 flubber
<int, int, int, short, short> ();
409 flubber
<int, int, int, short, long> ();
410 flubber
<int, int, int, short, char> ();
411 flubber
<int, int, int, long, int> ();
412 flubber
<int, int, int, long, short> ();
413 flubber
<int, int, int, long, long> ();
414 flubber
<int, int, int, long, char> ();
415 flubber
<int, int, int, char, int> ();
416 flubber
<int, int, int, char, short> ();
417 flubber
<int, int, int, char, long> ();
418 flubber
<int, int, int, char, char> ();
419 flubber
<int, int, short, int, int> ();
420 flubber
<int, int, short, int, short> ();
421 flubber
<int, int, short, int, long> ();
422 flubber
<int, int, short, int, char> ();
423 flubber
<int, int, short, short, int> ();
424 flubber
<short, int, short, int, short> ();
425 flubber
<long, short, long, short, long> ();
444 policyd5
pd5 (int_tclass
);
460 main (int argc
, char* argv
[])
464 /* Call the test function repeatedly, enough times for all our tests
465 without running forever if something goes wrong. */
466 for (i
= 0; i
< 1000; i
++)
467 test_function (argc
, argv
);
This page took 0.040082 seconds and 5 git commands to generate.