1 /* This test code is from Wendell Baker (wbaker@comet.berkeley.edu) */
2
3 #include <stddef.h>
4
5 int a_i;
6 char a_c;
7 double a_d;
8
9 typedef void *Pix;
10
11 int
f(int i)12 f(int i)
13 { return 0; }
14
15 int
f(int i,char c)16 f(int i, char c)
17 { return 0; }
18
19 int
f(int i,char c,double d)20 f(int i, char c, double d)
21 { return 0; }
22
23 int
f(int i,char c,double d,char * cs)24 f(int i, char c, double d, char *cs)
25 { return 0; }
26
27 int
f(int i,char c,double d,char * cs,void (* fig)(int,char))28 f(int i, char c, double d, char *cs, void (*fig)(int, char))
29 { return 0; }
30
31 int
f(int i,char c,double d,char * cs,void (* fig)(char,int))32 f(int i, char c, double d, char *cs, void (*fig)(char, int))
33 { return 0; }
34
35 class R {
36 public:
37 int i;
38 };
39 class S {
40 public:
41 int i;
42 };
43 class T {
44 public:
45 int i;
46 };
47
g(char,const char,volatile char)48 char g(char, const char, volatile char)
49 { return 'c'; }
g(R,char &,const char &,volatile char &)50 char g(R, char&, const char&, volatile char&)
51 { return 'c'; }
g(char *,const char *,volatile char *)52 char g(char*, const char*, volatile char*)
53 { return 'c'; }
g(S,char * &,const char * &,volatile char * &)54 char g(S, char*&, const char*&, volatile char*&)
55 { return 'c'; }
56
g(T,signed char,const signed char,volatile signed char)57 signed char g(T,signed char, const signed char, volatile signed char)
58 { return 'c'; }
g(T,R,signed char &,const signed char &,volatile signed char &)59 signed char g(T, R, signed char&, const signed char&, volatile signed char&)
60 { return 'c'; }
g(T,signed char *,const signed char *,volatile signed char *)61 signed char g(T, signed char*, const signed char*, volatile signed char*)
62 { return 'c'; }
g(T,S,signed char * &,const signed char * &,volatile signed char * &)63 signed char g(T, S, signed char*&, const signed char*&, volatile signed char*&)
64 { return 'c'; }
65
g(unsigned char,const unsigned char,volatile unsigned char)66 unsigned char g(unsigned char, const unsigned char, volatile unsigned char)
67 { return 'c'; }
g(R,unsigned char &,const unsigned char &,volatile unsigned char &)68 unsigned char g(R, unsigned char&, const unsigned char&, volatile unsigned char&)
69 { return 'c'; }
g(unsigned char *,const unsigned char *,volatile unsigned char *)70 unsigned char g(unsigned char*, const unsigned char*, volatile unsigned char*)
71 { return 'c'; }
g(S,unsigned char * &,const unsigned char * &,volatile unsigned char * &)72 unsigned char g(S, unsigned char*&, const unsigned char*&, volatile unsigned char*&)
73 { return 'c'; }
74
g(short,const short,volatile short)75 short g(short, const short, volatile short)
76 { return 0; }
g(R,short &,const short &,volatile short &)77 short g(R, short&, const short&, volatile short&)
78 { return 0; }
g(short *,const short *,volatile short *)79 short g(short*, const short*, volatile short*)
80 { return 0; }
g(S,short * &,const short * &,volatile short * &)81 short g(S, short*&, const short*&, volatile short*&)
82 { return 0; }
83
g(T,signed short,const signed short,volatile signed short)84 signed short g(T, signed short, const signed short, volatile signed short)
85 { return 0; }
g(T,R,signed short &,const signed short &,volatile signed short &)86 signed short g(T, R, signed short&, const signed short&, volatile signed short&)
87 { return 0; }
g(T,signed short *,const signed short *,volatile signed short *)88 signed short g(T, signed short*, const signed short*, volatile signed short*)
89 { return 0; }
g(T,S,double,signed short * &,const signed short * &,volatile signed short * &)90 signed short g(T, S, double, signed short*&, const signed short*&, volatile signed short*&)
91 { return 0; }
92
g(unsigned short,const unsigned short,volatile unsigned short)93 unsigned short g(unsigned short, const unsigned short, volatile unsigned short)
94 { return 0; }
g(R,unsigned short &,const unsigned short &,volatile unsigned short &)95 unsigned short g(R, unsigned short&, const unsigned short&, volatile unsigned short&)
96 { return 0; }
g(unsigned short *,const unsigned short *,volatile unsigned short *)97 unsigned short g(unsigned short*, const unsigned short*, volatile unsigned short*)
98 { return 0; }
g(S,unsigned short * &,const unsigned short * &,volatile unsigned short * &)99 unsigned short g(S, unsigned short*&, const unsigned short*&, volatile unsigned short*&)
100 { return 0; }
101
g(int,const int,volatile int)102 int g(int, const int, volatile int)
103 { return 0; }
g(R,int &,const int &,volatile int &)104 int g(R, int&, const int&, volatile int&)
105 { return 0; }
g(int *,const int *,volatile int *)106 int g(int*, const int*, volatile int*)
107 { return 0; }
g(S,int * &,const int * &,volatile int * &)108 int g(S, int*&, const int*&, volatile int*&)
109 { return 0; }
110
g(T,signed int,const signed int,volatile signed int)111 signed int g(T, signed int, const signed int, volatile signed int)
112 { return 0; }
g(T,R,signed int &,const signed int &,volatile signed int &)113 signed int g(T, R, signed int&, const signed int&, volatile signed int&)
114 { return 0; }
g(T,signed int *,const signed int *,volatile signed int *)115 signed int g(T, signed int*, const signed int*, volatile signed int*)
116 { return 0; }
g(T,S,signed int * &,const signed int * &,volatile signed int * &)117 signed int g(T, S, signed int*&, const signed int*&, volatile signed int*&)
118 { return 0; }
119
g(unsigned int,const unsigned int,volatile unsigned int)120 unsigned int g(unsigned int, const unsigned int, volatile unsigned int)
121 { return 0; }
g(R,unsigned int &,const unsigned int &,volatile unsigned int &)122 unsigned int g(R, unsigned int&, const unsigned int&, volatile unsigned int&)
123 { return 0; }
g(unsigned int *,const unsigned int *,volatile unsigned int *)124 unsigned int g(unsigned int*, const unsigned int*, volatile unsigned int*)
125 { return 0; }
g(S,unsigned int * &,const unsigned int * &,volatile unsigned int * &)126 unsigned int g(S, unsigned int*&, const unsigned int*&, volatile unsigned int*&)
127 { return 0; }
128
g(long,const long,volatile long)129 long g(long, const long, volatile long)
130 { return 0; }
g(R,long &,const long &,volatile long &)131 long g(R, long&, const long&, volatile long&)
132 { return 0; }
g(long *,const long *,volatile long *)133 long g(long*, const long*, volatile long*)
134 { return 0; }
g(S,long * &,const long * &,volatile long * &)135 long g(S, long*&, const long*&, volatile long*&)
136 { return 0; }
137
g(T,signed long,const signed long,volatile signed long)138 signed long g(T, signed long, const signed long, volatile signed long)
139 { return 0; }
g(T,R,signed long &,const signed long &,volatile signed long &)140 signed long g(T, R, signed long&, const signed long&, volatile signed long&)
141 { return 0; }
g(T,signed long *,const signed long *,volatile signed long *)142 signed long g(T, signed long*, const signed long*, volatile signed long*)
143 { return 0; }
g(T,S,signed long * &,const signed long * &,volatile signed long * &)144 signed long g(T, S, signed long*&, const signed long*&, volatile signed long*&)
145 { return 0; }
146
g(unsigned long,const unsigned long,volatile unsigned long)147 unsigned long g(unsigned long, const unsigned long, volatile unsigned long)
148 { return 0; }
g(S,unsigned long &,const unsigned long &,volatile unsigned long &)149 unsigned long g(S, unsigned long&, const unsigned long&, volatile unsigned long&)
150 { return 0; }
g(unsigned long *,const unsigned long *,volatile unsigned long *)151 unsigned long g(unsigned long*, const unsigned long*, volatile unsigned long*)
152 { return 0; }
g(S,unsigned long * &,const unsigned long * &,volatile unsigned long * &)153 unsigned long g(S, unsigned long*&, const unsigned long*&, volatile unsigned long*&)
154 { return 0; }
155
156 #ifdef __GNUC__
g(long long,const long long,volatile long long)157 long long g(long long, const long long, volatile long long)
158 { return 0; }
g(S,long long &,const long long &,volatile long long &)159 long long g(S, long long&, const long long&, volatile long long&)
160 { return 0; }
g(long long *,const long long *,volatile long long *)161 long long g(long long*, const long long*, volatile long long*)
162 { return 0; }
g(R,long long * &,const long long * &,volatile long long * &)163 long long g(R, long long*&, const long long*&, volatile long long*&)
164 { return 0; }
165
g(T,signed long long,const signed long long,volatile signed long long)166 signed long long g(T, signed long long, const signed long long, volatile signed long long)
167 { return 0; }
g(T,R,signed long long &,const signed long long &,volatile signed long long &)168 signed long long g(T, R, signed long long&, const signed long long&, volatile signed long long&)
169 { return 0; }
g(T,signed long long *,const signed long long *,volatile signed long long *)170 signed long long g(T, signed long long*, const signed long long*, volatile signed long long*)
171 { return 0; }
g(T,S,signed long long * &,const signed long long * &,volatile signed long long * &)172 signed long long g(T, S, signed long long*&, const signed long long*&, volatile signed long long*&)
173 { return 0; }
174
g(unsigned long long,const unsigned long long,volatile unsigned long long)175 unsigned long long g(unsigned long long, const unsigned long long, volatile unsigned long long)
176 { return 0; }
g(R,unsigned long long *,const unsigned long long *,volatile unsigned long long *)177 unsigned long long g(R, unsigned long long*, const unsigned long long*, volatile unsigned long long*)
178 { return 0; }
g(unsigned long long &,const unsigned long long &,volatile unsigned long long &)179 unsigned long long g(unsigned long long&, const unsigned long long&, volatile unsigned long long&)
180 { return 0; }
g(S,unsigned long long * &,const unsigned long long * &,volatile unsigned long long * &)181 unsigned long long g(S, unsigned long long*&, const unsigned long long*&, volatile unsigned long long*&)
182 { return 0; }
183 #endif
184
g(float,const float,volatile float)185 float g(float, const float, volatile float)
186 { return 0; }
g(char,float &,const float &,volatile float &)187 float g(char, float&, const float&, volatile float&)
188 { return 0; }
g(float *,const float *,volatile float *)189 float g(float*, const float*, volatile float*)
190 { return 0; }
g(char,float * &,const float * &,volatile float * &)191 float g(char, float*&, const float*&, volatile float*&)
192 { return 0; }
193
g(double,const double,volatile double)194 double g(double, const double, volatile double)
195 { return 0; }
g(char,double &,const double &,volatile double &)196 double g(char, double&, const double&, volatile double&)
197 { return 0; }
g(double *,const double *,volatile double *)198 double g(double*, const double*, volatile double*)
199 { return 0; }
g(char,double * &,const double * &,volatile double * &)200 double g(char, double*&, const double*&, volatile double*&)
201 { return 0; }
202
203 #ifdef __GNUC__
g(long double,const long double,volatile long double)204 long double g(long double, const long double, volatile long double)
205 { return 0; }
g(char,long double &,const long double &,volatile long double &)206 long double g(char, long double&, const long double&, volatile long double&)
207 { return 0; }
g(long double *,const long double *,volatile long double *)208 long double g(long double*, const long double*, volatile long double*)
209 { return 0; }
g(char,long double * &,const long double * &,volatile long double * &)210 long double g(char, long double*&, const long double*&, volatile long double*&)
211 { return 0; }
212 #endif
213
214 class c {
215 public:
c(int)216 c(int) {};
217 int i;
218 };
219
g(c,const c,volatile c)220 class c g(c, const c, volatile c)
221 { return 0; }
g(char,c &,const c &,volatile c &)222 c g(char, c&, const c&, volatile c&)
223 { return 0; }
g(c *,const c *,volatile c *)224 c g(c*, const c*, volatile c*)
225 { return 0; }
g(char,c * &,const c * &,volatile c * &)226 c g(char, c*&, const c*&, volatile c*&)
227 { return 0; }
228
229 /*
230 void h(char = 'a')
231 { }
232 void h(char, signed char = 'a')
233 { }
234 void h(unsigned char = 'a')
235 { }
236 */
237 /*
238 void h(char = (char)'a')
239 { }
240 void h(char, signed char = (signed char)'a')
241 { }
242 void h(unsigned char = (unsigned char)'a')
243 { }
244
245
246 void h(short = (short)43)
247 { }
248 void h(char, signed short = (signed short)43)
249 { }
250 void h(unsigned short = (unsigned short)43)
251 { }
252
253 void h(int = (int)43)
254 { }
255 void h(char, signed int = (signed int)43)
256 { }
257 void h(unsigned int = (unsigned int)43)
258 { }
259
260
261 void h(long = (long)43)
262 { }
263 void h(char, signed long = (signed long)43)
264 { }
265 void h(unsigned long = (unsigned long)43)
266 { }
267
268 #ifdef __GNUC__
269 void h(long long = 43)
270 { }
271 void h(char, signed long long = 43)
272 { }
273 void h(unsigned long long = 43)
274 { }
275 #endif
276
277 void h(float = 4.3e-10)
278 { }
279 void h(double = 4.3)
280 { }
281 #ifdef __GNUC__
282 void h(long double = 4.33e33)
283 { }
284 #endif
285 */
286
287 /* An unneeded printf() definition - actually, just a stub - used to occupy
288 this space. It has been removed and replaced with this comment which
289 exists to occupy some lines so that templates.exp won't need adjustment. */
290
291 class T1 {
292 public:
293 static void* operator new(size_t) throw ();
294 static void operator delete(void *pointer);
295
296 void operator=(const T1&);
297 T1& operator=(int);
298
299 int operator==(int) const;
300 int operator==(const T1&) const;
301 int operator!=(int) const;
302 int operator!=(const T1&) const;
303
304 int operator<=(int) const;
305 int operator<=(const T1&) const;
306 int operator<(int) const;
307 int operator<(const T1&) const;
308 int operator>=(int) const;
309 int operator>=(const T1&) const;
310 int operator>(int) const;
311 int operator>(const T1&) const;
312
313 void operator+(int) const;
314 T1& operator+(const T1&) const;
315 void operator+=(int) const;
316 T1& operator+=(const T1&) const;
317
318 T1& operator++() const;
319
320 void operator-(int) const;
321 T1& operator-(const T1&) const;
322 void operator-=(int) const;
323 T1& operator-=(const T1&) const;
324
325 T1& operator--() const;
326
327 void operator*(int) const;
328 T1& operator*(const T1&) const;
329 void operator*=(int) const;
330 T1& operator*=(const T1&) const;
331
332 void operator/(int) const;
333 T1& operator/(const T1&) const;
334 void operator/=(int) const;
335 T1& operator/=(const T1&) const;
336
337 void operator%(int) const;
338 T1& operator%(const T1&) const;
339 void operator%=(int) const;
340 T1& operator%=(const T1&) const;
341
342 void operator&&(int) const;
343 T1& operator&&(const T1&) const;
344
345 void operator||(int) const;
346 T1& operator||(const T1&) const;
347
348 void operator&(int) const;
349 T1& operator&(const T1&) const;
350 void operator&=(int) const;
351 T1& operator&=(const T1&) const;
352
353 void operator|(int) const;
354 T1& operator|(const T1&) const;
355 void operator|=(int) const;
356 T1& operator|=(const T1&) const;
357
358 void operator^(int) const;
359 T1& operator^(const T1&) const;
360 void operator^=(int) const;
361 T1& operator^=(const T1&) const;
362
363 T1& operator!() const;
364 T1& operator~() const;
365 };
366
367 void*
operator new(size_t)368 T1::operator new(size_t) throw ()
369 { return 0; }
370
371 void
operator delete(void * pointer)372 T1::operator delete(void *pointer)
373 { }
374
375 class T2 {
376 public:
T2(int i)377 T2(int i): integer(i)
378 { }
379 int integer;
380 };
381
operator ==(const T2 &,const T2 &)382 int operator==(const T2&, const T2&)
383 { return 0; }
operator ==(const T2 &,char)384 int operator==(const T2&, char)
385 { return 0; }
operator !=(const T2 &,const T2 &)386 int operator!=(const T2&, const T2&)
387 { return 0; }
operator !=(const T2 &,char)388 int operator!=(const T2&, char)
389 { return 0; }
390
operator <=(const T2 &,const T2 &)391 int operator<=(const T2&, const T2&)
392 { return 0; }
operator <=(const T2 &,char)393 int operator<=(const T2&, char)
394 { return 0; }
operator <(const T2 &,const T2 &)395 int operator<(const T2&, const T2&)
396 { return 0; }
operator <(const T2 &,char)397 int operator<(const T2&, char)
398 { return 0; }
operator >=(const T2 &,const T2 &)399 int operator>=(const T2&, const T2&)
400 { return 0; }
operator >=(const T2 &,char)401 int operator>=(const T2&, char)
402 { return 0; }
operator >(const T2 &,const T2 &)403 int operator>(const T2&, const T2&)
404 { return 0; }
operator >(const T2 &,char)405 int operator>(const T2&, char)
406 { return 0; }
407
operator +(const T2 t,int i)408 T2 operator+(const T2 t, int i)
409 { return t.integer + i; }
operator +(const T2 a,const T2 & b)410 T2 operator+(const T2 a, const T2& b)
411 { return a.integer + b.integer; }
operator +=(T2 & t,int i)412 T2& operator+=(T2& t, int i)
413 { t.integer += i; return t; }
operator +=(T2 & a,const T2 & b)414 T2& operator+=(T2& a, const T2& b)
415 { a.integer += b.integer; return a; }
416
operator -(const T2 t,int i)417 T2 operator-(const T2 t, int i)
418 { return t.integer - i; }
operator -(const T2 a,const T2 & b)419 T2 operator-(const T2 a, const T2& b)
420 { return a.integer - b.integer; }
operator -=(T2 & t,int i)421 T2& operator-=(T2& t, int i)
422 { t.integer -= i; return t; }
operator -=(T2 & a,const T2 & b)423 T2& operator-=(T2& a, const T2& b)
424 { a.integer -= b.integer; return a; }
425
operator *(const T2 t,int i)426 T2 operator*(const T2 t, int i)
427 { return t.integer * i; }
operator *(const T2 a,const T2 & b)428 T2 operator*(const T2 a, const T2& b)
429 { return a.integer * b.integer; }
operator *=(T2 & t,int i)430 T2& operator*=(T2& t, int i)
431 { t.integer *= i; return t; }
operator *=(T2 & a,const T2 & b)432 T2& operator*=(T2& a, const T2& b)
433 { a.integer *= b.integer; return a; }
434
operator /(const T2 t,int i)435 T2 operator/(const T2 t, int i)
436 { return t.integer / i; }
operator /(const T2 a,const T2 & b)437 T2 operator/(const T2 a, const T2& b)
438 { return a.integer / b.integer; }
operator /=(T2 & t,int i)439 T2& operator/=(T2& t, int i)
440 { t.integer /= i; return t; }
operator /=(T2 & a,const T2 & b)441 T2& operator/=(T2& a, const T2& b)
442 { a.integer /= b.integer; return a; }
443
operator %(const T2 t,int i)444 T2 operator%(const T2 t, int i)
445 { return t.integer % i; }
operator %(const T2 a,const T2 & b)446 T2 operator%(const T2 a, const T2& b)
447 { return a.integer % b.integer; }
operator %=(T2 & t,int i)448 T2& operator%=(T2& t, int i)
449 { t.integer %= i; return t; }
operator %=(T2 & a,const T2 & b)450 T2& operator%=(T2& a, const T2& b)
451 { a.integer %= b.integer; return a; }
452
453 template<class T>
454 class T5 {
455 public:
456 T5(int);
457 T5(const T5<T>&);
458 ~T5();
459 static void* operator new(size_t) throw ();
460 static void operator delete(void *pointer);
461 int value();
462
463 static T X;
464 T x;
465 int val;
466 };
467
468 template<class T>
T5(int v)469 T5<T>::T5(int v)
470 { val = v; }
471
472 template<class T>
T5(const T5<T> &)473 T5<T>::T5(const T5<T>&)
474 {}
475
476 template<class T>
~T5()477 T5<T>::~T5()
478 {}
479
480 template<class T>
481 void*
operator new(size_t)482 T5<T>::operator new(size_t) throw ()
483 { return 0; }
484
485 template<class T>
486 void
operator delete(void * pointer)487 T5<T>::operator delete(void *pointer)
488 { }
489
490 template<class T>
491 int
value()492 T5<T>::value()
493 { return val; }
494
495 template <class T>
GetMax(T a,T b)496 T GetMax (T a, T b) {
497 T result;
498 result = (a>b)? a : b;
499 // set breakpoint on a line with no real code
500 return (result);
501 }
502
503 #if ! defined(__GNUC__) || defined(GCC_BUG)
504 template<class T>
505 T T5<T>::X;
506 #endif
507
508
509
510
511 T5<char> t5c(1);
512 T5<int> t5i(2);
513 T5<int (*)(char, void *)> t5fi1(3);
514 T5<int (*)(int, double **, void *)> t5fi2(4);
515
516
517
518
519
520
521 class x {
522 public:
523 int (*manage[5])(double,
524 void *(*malloc)(unsigned size),
525 void (*free)(void *pointer));
526 int (*device[5])(int open(const char *, unsigned mode, unsigned perms, int extra),
527 int *(*read)(int fd, void *place, unsigned size),
528 int *(*write)(int fd, void *place, unsigned size),
529 void (*close)(int fd));
530 };
531 T5<x> t5x(5);
532
533 #if !defined(__GNUC__) || (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)
534 template class T5<char>;
535 template class T5<int>;
536 template class T5<int (*)(char, void *)>;
537 template class T5<int (*)(int, double **, void *)>;
538 template class T5<x>;
539 #endif
540
541 class T7 {
542 public:
543 static int get();
544 static void put(int);
545 };
546
547 int
get()548 T7::get()
549 { return 1; }
550
551 void
put(int i)552 T7::put(int i)
553 {
554 // nothing
555 }
556
557 // More template kinds. GDB 4.16 didn't handle these, but
558 // Wildebeest does. Note: Assuming HP aCC is used to compile
559 // this file; with g++ or HP cfront or other compilers the
560 // demangling may not get done correctly.
561
562 // Ordinary template, to be instantiated with different types
563 template<class T>
564 class Foo {
565 public:
566 int x;
567 T t;
568 T foo (int, T);
569 };
570
571
foo(int i,T tt)572 template<class T> T Foo<T>::foo (int i, T tt)
573 {
574 return tt;
575 }
576
577 // Template with int parameter
578
579 template<class T, int sz>
580 class Bar {
581 public:
582 int x;
583 T t;
584 T bar (int, T);
585 };
586
587
bar(int i,T tt)588 template<class T, int sz> T Bar<T, sz>::bar (int i, T tt)
589 {
590 if (i < sz)
591 return tt;
592 else
593 return 0;
594 }
595
596 // function template with int parameter
dummy(T tt,int i)597 template<class T> int dummy (T tt, int i)
598 {
599 return tt;
600 }
601
602 // Template with partial specializations
603 template<class T1, class T2>
604 class Spec {
605 public:
606 int x;
607 T1 spec (T2);
608 };
609
610 template<class T1, class T2>
spec(T2 t2)611 T1 Spec<T1, T2>::spec (T2 t2)
612 {
613 return 0;
614 }
615
616 template<class T>
617 class Spec<T, T*> {
618 public:
619 int x;
620 T spec (T*);
621 };
622
623 template<class T>
spec(T * tp)624 T Spec<T, T*>::spec (T * tp)
625 {
626 return *tp;
627 }
628
629 // Template with char parameter
630 template<class T, char sz>
631 class Baz {
632 public:
~Baz()633 ~Baz () { };
634 int x;
635 T t;
636 T baz (int, T);
637 };
638
baz(int i,T tt)639 template<class T, char sz> T Baz<T, sz>::baz (int i, T tt)
640 {
641 if (i < sz)
642 return tt;
643 else
644 return 0;
645 }
646
647 typedef Baz<int, 1> intBazOne;
648
649 // Template with char * parameter
650 template<class T, char * sz>
651 class Qux {
652 public:
653 int x;
654 T t;
655 T qux (int, T);
656 };
657
qux(int i,T tt)658 template<class T, char * sz> T Qux<T, sz>::qux (int i, T tt)
659 {
660 if (sz[0] == 'q')
661 return tt;
662 else
663 return 0;
664 }
665
666 // Template with a function pointer parameter
667 template<class T, int (*f)(int) >
668 class Qux1 {
669 public:
670 int x;
671 T t;
672 T qux (int, T);
673 };
674
qux(int i,T tt)675 template<class T, int (*f)(int)> T Qux1<T, f>::qux (int i, T tt)
676 {
677 if (f != 0)
678 return tt;
679 else
680 return 0;
681 }
682
683 // Some functions to provide as arguments to template
gf1(int a)684 int gf1 (int a) {
685 return a * 2 + 13;
686 }
gf2(int a)687 int gf2 (int a) {
688 return a * 2 + 26;
689 }
690
691 char string[3];
692
693 // Template class with typedefs and const attributes.
694 template<typename DataT>
695 class Cfoo
696 {
697 typedef float myfloat;
698 public:
699 DataT me0;
700 const DataT me1=1;
701 const myfloat me2=2.0;
702 const int me3=0;
703 };
704
705
706 // Template for nested instantiations
707
708 template<class T>
709 class Garply {
710 public:
711 int x;
712 T t;
713 T garply (int, T);
714 };
715
garply(int i,T tt)716 template<class T> T Garply<T>::garply (int i, T tt)
717 {
718 if (i > x)
719 return tt;
720 else
721 {
722 x += i;
723 return tt;
724 }
725 }
726
727 template<class C> class Empty
728 {
729 };
730
731 template<class C> class FunctionArg
732 {
733 public:
734 int method(Empty<void (FunctionArg<C>)> &);
735 };
736
method(Empty<void (FunctionArg<C>)> & arg)737 template<class C> int FunctionArg<C>::method(Empty<void (FunctionArg<C>)> &arg)
738 {
739 return 75;
740 }
741
742 Empty<void(FunctionArg<int>)> empty;
743 FunctionArg<int> arg;
744
745 template <typename T1>
746 struct Foozle
747 {
748 int x;
749 T1 t;
750 template <typename T2>
751 T2 fogey (T2 plop);
752 };
753
754 template <typename T1>
755 template <typename T2>
fogey(T2 plop)756 T2 Foozle<T1>::fogey (T2 plop)
757 {
758 return plop;
759 }
760
761 template <typename T>
operator <(T & lhs,T & rhs)762 int operator< (T &lhs, T &rhs)
763 {
764 return 0;
765 }
766
767 template <typename T>
operator <<(T & obj,T & val)768 int operator<< (T &obj, T &val)
769 {
770 return 1;
771 };
772
main()773 int main()
774 {
775 int i;
776 long l, m, n;
777
778 i = i + 1;
779
780 // New tests added here
781
782 Foo<int> fint={0,0};
783 Foo<char> fchar={0,0};
784 Foo<volatile char *> fvpchar = {0, 0};
785
786 Bar<int, 33> bint;
787 Bar<int, (4 > 3)> bint2;
788
789 Baz<int, 's'> bazint;
790 Baz<char, 'a'> bazint2;
791
792 Qux<char, string> quxint2;
793 Qux<int, string> quxint;
794
795 Qux1<int, gf1> qux11;
796
797 int x = fint.foo(33, 47);
798 char c = fchar.foo(33, 'x');
799 volatile char * cp = fvpchar.foo(33, 0);
800
801 int y = dummy<int> (400, 600);
802
803 int z = bint.bar(55, 66);
804 z += bint2.bar(55, 66);
805
806 c = bazint2.baz(4, 'y');
807 c = quxint2.qux(4, 'z');
808
809 y = bazint.baz(4,3);
810 y = quxint.qux(4, 22);
811 y += qux11.qux(4, 22);
812
813 y *= gf1(y) - gf2(y);
814
815 Spec<int, char> sic;
816 Spec<int, int *> siip;
817
818 sic.spec ('c');
819 siip.spec (&x);
820
821 Cfoo<double> cfoo;
822
823 Garply<int> f;
824 Garply<char> fc;
825 f.x = 13;
826
827 Garply<Garply<char> > nf;
828 nf.x = 31;
829
830 x = f.garply (3, 4);
831
832 fc = nf.garply (3, fc);
833
834 y = x + fc.x;
835
836 i=GetMax<int>(x,y);
837 n=GetMax<long>(l,m);
838
839 intBazOne ibo;
840 z = ibo.baz (2, 21);
841
842 t5i.value();
843
844 arg.method(empty);
845
846 Empty<int> e;
847 Foozle<int> fzi;
848 x = fzi.fogey (0);
849 c = fzi.fogey<char> ('a');
850 e = fzi.fogey<Empty<int>> (e);
851 Foozle<char> fzc;
852 c = fzc.fogey ('b');
853 x = fzc.fogey<int> (0);
854 e = fzc.fogey<Empty<int>> (e);
855 Foozle<Empty<int>> fze;
856 e = fze.fogey (e);
857 c = fze.fogey<char> ('c');
858 x = fze.fogey<int> (0);
859
860 z = e < e;
861 z += e << e;
862 z += fzi < fzi;
863 z += fzi << fzi;
864
865 return 0; /* Final breakpoint. */
866 }
867