1/* This test code is from Wendell Baker (wbaker@comet.berkeley.edu) */
2
3#include <stddef.h>
4
5int a_i;
6char a_c;
7double a_d;
8
9typedef void *Pix;
10
11int
12f(int i)
13{ return 0; }
14
15int
16f(int i, char c)
17{ return 0; }
18
19int
20f(int i, char c, double d)
21{ return 0; }
22
23int
24f(int i, char c, double d, char *cs)
25{ return 0; }
26
27int
28f(int i, char c, double d, char *cs, void (*fig)(int, char))
29{ return 0; }
30
31int
32f(int i, char c, double d, char *cs, void (*fig)(char, int))
33{ return 0; }
34
35class R {
36public:
37    int i;
38};
39class S {
40public:
41    int i;
42};
43class T {
44public:
45    int i;
46};
47
48char g(char, const char, volatile char)
49{ return 'c'; }
50char g(R, char&, const char&, volatile char&)
51{ return 'c'; }
52char g(char*, const char*, volatile char*)
53{ return 'c'; }
54char g(S, char*&, const char*&, volatile char*&)
55{ return 'c'; }
56
57signed char g(T,signed char, const signed char, volatile signed char)
58{ return 'c'; }
59signed char g(T, R, signed char&, const signed char&, volatile signed char&)
60{ return 'c'; }
61signed char g(T, signed char*, const signed char*, volatile signed char*)
62{ return 'c'; }
63signed char g(T, S, signed char*&, const signed char*&, volatile signed char*&)
64{ return 'c'; }
65
66unsigned char g(unsigned char, const unsigned char, volatile unsigned char)
67{ return 'c'; }
68unsigned char g(R, unsigned char&, const unsigned char&, volatile unsigned char&)
69{ return 'c'; }
70unsigned char g(unsigned char*, const unsigned char*, volatile unsigned char*)
71{ return 'c'; }
72unsigned char g(S, unsigned char*&, const unsigned char*&, volatile unsigned char*&)
73{ return 'c'; }
74
75short g(short, const short, volatile short)
76{ return 0; }
77short g(R, short&, const short&, volatile short&)
78{ return 0; }
79short g(short*, const short*, volatile short*)
80{ return 0; }
81short g(S, short*&, const short*&, volatile short*&)
82{ return 0; }
83
84signed short g(T, signed short, const signed short, volatile signed short)
85{ return 0; }
86signed short g(T, R, signed short&, const signed short&, volatile signed short&)
87{ return 0; }
88signed short g(T, signed short*, const signed short*, volatile signed short*)
89{ return 0; }
90signed short g(T, S, double, signed short*&, const signed short*&, volatile signed short*&)
91{ return 0; }
92
93unsigned short g(unsigned short, const unsigned short, volatile unsigned short)
94{ return 0; }
95unsigned short g(R, unsigned short&, const unsigned short&, volatile unsigned short&)
96{ return 0; }
97unsigned short g(unsigned short*, const unsigned short*, volatile unsigned short*)
98{ return 0; }
99unsigned short g(S, unsigned short*&, const unsigned short*&, volatile unsigned short*&)
100{ return 0; }
101
102int g(int, const int, volatile int)
103{ return 0; }
104int g(R, int&, const int&, volatile int&)
105{ return 0; }
106int g(int*, const int*, volatile int*)
107{ return 0; }
108int g(S, int*&, const int*&, volatile int*&)
109{ return 0; }
110
111signed int g(T, signed int, const signed int, volatile signed int)
112{ return 0; }
113signed int g(T, R, signed int&, const signed int&, volatile signed int&)
114{ return 0; }
115signed int g(T, signed int*, const signed int*, volatile signed int*)
116{ return 0; }
117signed int g(T, S, signed int*&, const signed int*&, volatile signed int*&)
118{ return 0; }
119
120unsigned int g(unsigned int, const unsigned int, volatile unsigned int)
121{ return 0; }
122unsigned int g(R, unsigned int&, const unsigned int&, volatile unsigned int&)
123{ return 0; }
124unsigned int g(unsigned int*, const unsigned int*, volatile unsigned int*)
125{ return 0; }
126unsigned int g(S, unsigned int*&, const unsigned int*&, volatile unsigned int*&)
127{ return 0; }
128
129long g(long, const long, volatile long)
130{ return 0; }
131long g(R, long&, const long&, volatile long&)
132{ return 0; }
133long g(long*, const long*, volatile long*)
134{ return 0; }
135long g(S, long*&, const long*&, volatile long*&)
136{ return 0; }
137
138signed long g(T, signed long, const signed long, volatile signed long)
139{ return 0; }
140signed long g(T, R, signed long&, const signed long&, volatile signed long&)
141{ return 0; }
142signed long g(T, signed long*, const signed long*, volatile signed long*)
143{ return 0; }
144signed long g(T, S, signed long*&, const signed long*&, volatile signed long*&)
145{ return 0; }
146
147unsigned long g(unsigned long, const unsigned long, volatile unsigned long)
148{ return 0; }
149unsigned long g(S, unsigned long&, const unsigned long&, volatile unsigned long&)
150{ return 0; }
151unsigned long g(unsigned long*, const unsigned long*, volatile unsigned long*)
152{ return 0; }
153unsigned long g(S, unsigned long*&, const unsigned long*&, volatile unsigned long*&)
154{ return 0; }
155
156#ifdef __GNUC__
157long long g(long long, const long long, volatile long long)
158{ return 0; }
159long long g(S, long long&, const long long&, volatile long long&)
160{ return 0; }
161long long g(long long*, const long long*, volatile long long*)
162{ return 0; }
163long long g(R, long long*&, const long long*&, volatile long long*&)
164{ return 0; }
165
166signed long long g(T, signed long long, const signed long long, volatile signed long long)
167{ return 0; }
168signed long long g(T, R, signed long long&, const signed long long&, volatile signed long long&)
169{ return 0; }
170signed long long g(T, signed long long*, const signed long long*, volatile signed long long*)
171{ return 0; }
172signed long long g(T, S, signed long long*&, const signed long long*&, volatile signed long long*&)
173{ return 0; }
174
175unsigned long long g(unsigned long long, const unsigned long long, volatile unsigned long long)
176{ return 0; }
177unsigned long long g(R, unsigned long long*, const unsigned long long*, volatile unsigned long long*)
178{ return 0; }
179unsigned long long g(unsigned long long&, const unsigned long long&, volatile unsigned long long&)
180{ return 0; }
181unsigned long long g(S, unsigned long long*&, const unsigned long long*&, volatile unsigned long long*&)
182{ return 0; }
183#endif
184
185float g(float, const float, volatile float)
186{ return 0; }
187float g(char, float&, const float&, volatile float&)
188{ return 0; }
189float g(float*, const float*, volatile float*)
190{ return 0; }
191float g(char, float*&, const float*&, volatile float*&)
192{ return 0; }
193
194double g(double, const double, volatile double)
195{ return 0; }
196double g(char, double&, const double&, volatile double&)
197{ return 0; }
198double g(double*, const double*, volatile double*)
199{ return 0; }
200double g(char, double*&, const double*&, volatile double*&)
201{ return 0; }
202
203#ifdef __GNUC__
204long double g(long double, const long double, volatile long double)
205{ return 0; }
206long double g(char, long double&, const long double&, volatile long double&)
207{ return 0; }
208long double g(long double*, const long double*, volatile long double*)
209{ return 0; }
210long double g(char, long double*&, const long double*&, volatile long double*&)
211{ return 0; }
212#endif
213
214class c {
215public:
216    c(int) {};
217    int i;
218};
219
220class c g(c, const c, volatile c)
221{ return 0; }
222c g(char, c&, const c&, volatile c&)
223{ return 0; }
224c g(c*, const c*, volatile c*)
225{ return 0; }
226c g(char, c*&, const c*&, volatile c*&)
227{ return 0; }
228
229/*
230void h(char = 'a')
231{ }
232void h(char, signed char = 'a')
233{ }
234void h(unsigned char = 'a')
235{ }
236*/
237/*
238void h(char = (char)'a')
239{ }
240void h(char, signed char = (signed char)'a')
241{ }
242void h(unsigned char = (unsigned char)'a')
243{ }
244
245
246void h(short = (short)43)
247{ }
248void h(char, signed short = (signed short)43)
249{ }
250void h(unsigned short = (unsigned short)43)
251{ }
252
253void h(int = (int)43)
254{ }
255void h(char, signed int = (signed int)43)
256{ }
257void h(unsigned int = (unsigned int)43)
258{ }
259
260
261void h(long = (long)43)
262{ }
263void h(char, signed long = (signed long)43)
264{ }
265void h(unsigned long = (unsigned long)43)
266{ }
267
268#ifdef __GNUC__
269void h(long long = 43)
270{ }
271void h(char, signed long long = 43)
272{ }
273void h(unsigned long long = 43)
274{ }
275#endif
276
277void h(float = 4.3e-10)
278{ }
279void h(double = 4.3)
280{ }
281#ifdef __GNUC__
282void 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
291class T1 {
292public:
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
367void*
368T1::operator new(size_t) throw ()
369{ return 0; }
370
371void
372T1::operator delete(void *pointer)
373{ }
374
375class T2 {
376public:
377    T2(int i): integer(i)
378	{ }
379    int integer;
380};
381
382int operator==(const T2&, const T2&)
383{ return 0; }
384int operator==(const T2&, char)
385{ return 0; }
386int operator!=(const T2&, const T2&)
387{ return 0; }
388int operator!=(const T2&, char)
389{ return 0; }
390
391int operator<=(const T2&, const T2&)
392{ return 0; }
393int operator<=(const T2&, char)
394{ return 0; }
395int operator<(const T2&, const T2&)
396{ return 0; }
397int operator<(const T2&, char)
398{ return 0; }
399int operator>=(const T2&, const T2&)
400{ return 0; }
401int operator>=(const T2&, char)
402{ return 0; }
403int operator>(const T2&, const T2&)
404{ return 0; }
405int operator>(const T2&, char)
406{ return 0; }
407
408T2 operator+(const T2 t, int i)
409{ return t.integer + i; }
410T2 operator+(const T2 a, const T2& b)
411{ return a.integer + b.integer; }
412T2& operator+=(T2& t, int i)
413{ t.integer += i; return t; }
414T2& operator+=(T2& a, const T2& b)
415{ a.integer += b.integer; return a; }
416
417T2 operator-(const T2 t, int i)
418{ return t.integer - i; }
419T2 operator-(const T2 a, const T2& b)
420{ return a.integer - b.integer; }
421T2& operator-=(T2& t, int i)
422{ t.integer -= i; return t; }
423T2& operator-=(T2& a, const T2& b)
424{ a.integer -= b.integer; return a; }
425
426T2 operator*(const T2 t, int i)
427{ return t.integer * i; }
428T2 operator*(const T2 a, const T2& b)
429{ return a.integer * b.integer; }
430T2& operator*=(T2& t, int i)
431{ t.integer *= i; return t; }
432T2& operator*=(T2& a, const T2& b)
433{ a.integer *= b.integer; return a; }
434
435T2 operator/(const T2 t, int i)
436{ return t.integer / i; }
437T2 operator/(const T2 a, const T2& b)
438{ return a.integer / b.integer; }
439T2& operator/=(T2& t, int i)
440{ t.integer /= i; return t; }
441T2& operator/=(T2& a, const T2& b)
442{ a.integer /= b.integer; return a; }
443
444T2 operator%(const T2 t, int i)
445{ return t.integer % i; }
446T2 operator%(const T2 a, const T2& b)
447{ return a.integer % b.integer; }
448T2& operator%=(T2& t, int i)
449{ t.integer %= i; return t; }
450T2& operator%=(T2& a, const T2& b)
451{ a.integer %= b.integer; return a; }
452
453template<class T>
454class T5 {
455public:
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
468template<class T>
469T5<T>::T5(int v)
470{ val = v; }
471
472template<class T>
473T5<T>::T5(const T5<T>&)
474{}
475
476template<class T>
477T5<T>::~T5()
478{}
479
480template<class T>
481void*
482T5<T>::operator new(size_t) throw ()
483{ return 0; }
484
485template<class T>
486void
487T5<T>::operator delete(void *pointer)
488{ }
489
490template<class T>
491int
492T5<T>::value()
493{ return val; }
494
495template <class T>
496T 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)
504template<class T>
505T T5<T>::X;
506#endif
507
508
509
510
511T5<char> t5c(1);
512T5<int> t5i(2);
513T5<int (*)(char, void *)> t5fi1(3);
514T5<int (*)(int, double **, void *)> t5fi2(4);
515
516
517
518
519
520
521class x {
522public:
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};
531T5<x> t5x(5);
532
533#if !defined(__GNUC__) || (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)
534template class T5<char>;
535template class T5<int>;
536template class T5<int (*)(char, void *)>;
537template class T5<int (*)(int, double **, void *)>;
538template class T5<x>;
539#endif
540
541class T7 {
542public:
543    static int get();
544    static void put(int);
545};
546
547int
548T7::get()
549{ return 1; }
550
551void
552T7::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
563template<class T>
564class Foo {
565public:
566  int x;
567  T t;
568  T foo (int, T);
569};
570
571
572template<class T> T Foo<T>::foo (int i, T tt)
573{
574  return tt;
575}
576
577// Template with int parameter
578
579template<class T, int sz>
580class Bar {
581public:
582  int x;
583  T t;
584  T bar (int, T);
585};
586
587
588template<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
597template<class T> int dummy (T tt, int i)
598{
599  return tt;
600}
601
602// Template with partial specializations
603template<class T1, class T2>
604class Spec {
605public:
606  int x;
607  T1 spec (T2);
608};
609
610template<class T1, class T2>
611T1 Spec<T1, T2>::spec (T2 t2)
612{
613  return 0;
614}
615
616template<class T>
617class Spec<T, T*> {
618public:
619  int x;
620  T spec (T*);
621};
622
623template<class T>
624T Spec<T, T*>::spec (T * tp)
625{
626  return *tp;
627}
628
629// Template with char parameter
630template<class T, char sz>
631class Baz {
632public:
633  ~Baz () { };
634  int x;
635  T t;
636  T baz (int, T);
637};
638
639template<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
647typedef Baz<int, 1> intBazOne;
648
649// Template with char * parameter
650template<class T, char * sz>
651class Qux {
652public:
653  int x;
654  T t;
655  T qux (int, T);
656};
657
658template<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
667template<class T, int (*f)(int) >
668class Qux1 {
669public:
670  int x;
671  T t;
672  T qux (int, T);
673};
674
675template<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
684int gf1 (int a) {
685  return a * 2 + 13;
686}
687int gf2 (int a) {
688  return a * 2 + 26;
689}
690
691char string[3];
692
693
694// Template for nested instantiations
695
696template<class T>
697class Garply {
698public:
699  int x;
700  T t;
701  T garply (int, T);
702};
703
704template<class T> T Garply<T>::garply (int i, T tt)
705{
706  if (i > x)
707    return tt;
708  else
709    {
710      x += i;
711      return tt;
712    }
713}
714
715template<class C> class Empty
716{
717};
718
719template<class C> class FunctionArg
720{
721public:
722  int method(Empty<void (FunctionArg<C>)> &);
723};
724
725template<class C> int FunctionArg<C>::method(Empty<void (FunctionArg<C>)> &arg)
726{
727  return 75;
728}
729
730Empty<void(FunctionArg<int>)> empty;
731FunctionArg<int> arg;
732
733int main()
734{
735    int i;
736    long l, m, n;
737#ifdef usestubs
738    set_debug_traps();
739    breakpoint();
740#endif
741    i = i + 1;
742
743    // New tests added here
744
745  Foo<int> fint={0,0};
746  Foo<char> fchar={0,0};
747  Foo<volatile char *> fvpchar = {0, 0};
748
749  Bar<int, 33> bint;
750  Bar<int, (4 > 3)> bint2;
751
752  Baz<int, 's'> bazint;
753  Baz<char, 'a'> bazint2;
754
755  Qux<char, string> quxint2;
756  Qux<int, string> quxint;
757
758  Qux1<int, gf1> qux11;
759
760  int x = fint.foo(33, 47);
761  char c = fchar.foo(33, 'x');
762  volatile char * cp = fvpchar.foo(33, 0);
763
764  int y = dummy<int> (400, 600);
765
766  int z = bint.bar(55, 66);
767  z += bint2.bar(55, 66);
768
769  c = bazint2.baz(4, 'y');
770  c = quxint2.qux(4, 'z');
771
772  y = bazint.baz(4,3);
773  y = quxint.qux(4, 22);
774  y += qux11.qux(4, 22);
775
776  y *= gf1(y) - gf2(y);
777
778  Spec<int, char> sic;
779  Spec<int, int *> siip;
780
781  sic.spec ('c');
782  siip.spec (&x);
783
784  Garply<int> f;
785  Garply<char> fc;
786  f.x = 13;
787
788  Garply<Garply<char> > nf;
789  nf.x = 31;
790
791  x = f.garply (3, 4);
792
793  fc = nf.garply (3, fc);
794
795  y = x + fc.x;
796
797  i=GetMax<int>(x,y);
798  n=GetMax<long>(l,m);
799
800  intBazOne ibo;
801  z = ibo.baz (2, 21);
802
803  t5i.value();
804
805  arg.method(empty);
806
807  return 0;
808}
809