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 495 496#if ! defined(__GNUC__) || defined(GCC_BUG) 497template<class T> 498T T5<T>::X; 499#endif 500 501 502 503 504T5<char> t5c(1); 505T5<int> t5i(2); 506T5<int (*)(char, void *)> t5fi1(3); 507T5<int (*)(int, double **, void *)> t5fi2(4); 508 509 510 511 512 513 514class x { 515public: 516 int (*manage[5])(double, 517 void *(*malloc)(unsigned size), 518 void (*free)(void *pointer)); 519 int (*device[5])(int open(const char *, unsigned mode, unsigned perms, int extra), 520 int *(*read)(int fd, void *place, unsigned size), 521 int *(*write)(int fd, void *place, unsigned size), 522 void (*close)(int fd)); 523}; 524T5<x> t5x(5); 525 526#if !defined(__GNUC__) || (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6) 527template class T5<char>; 528template class T5<int>; 529template class T5<int (*)(char, void *)>; 530template class T5<int (*)(int, double **, void *)>; 531template class T5<x>; 532#endif 533 534class T7 { 535public: 536 static int get(); 537 static void put(int); 538}; 539 540int 541T7::get() 542{ return 1; } 543 544void 545T7::put(int i) 546{ 547 // nothing 548} 549 550// More template kinds. GDB 4.16 didn't handle these, but 551// Wildebeest does. Note: Assuming HP aCC is used to compile 552// this file; with g++ or HP cfront or other compilers the 553// demangling may not get done correctly. 554 555// Ordinary template, to be instantiated with different types 556template<class T> 557class Foo { 558public: 559 int x; 560 T t; 561 T foo (int, T); 562}; 563 564 565template<class T> T Foo<T>::foo (int i, T tt) 566{ 567 return tt; 568} 569 570// Template with int parameter 571 572template<class T, int sz> 573class Bar { 574public: 575 int x; 576 T t; 577 T bar (int, T); 578}; 579 580 581template<class T, int sz> T Bar<T, sz>::bar (int i, T tt) 582{ 583 if (i < sz) 584 return tt; 585 else 586 return 0; 587} 588 589// function template with int parameter 590template<class T> int dummy (T tt, int i) 591{ 592 return tt; 593} 594 595// Template with partial specializations 596template<class T1, class T2> 597class Spec { 598public: 599 int x; 600 T1 spec (T2); 601}; 602 603template<class T1, class T2> 604T1 Spec<T1, T2>::spec (T2 t2) 605{ 606 return 0; 607} 608 609template<class T> 610class Spec<T, T*> { 611public: 612 int x; 613 T spec (T*); 614}; 615 616template<class T> 617T Spec<T, T*>::spec (T * tp) 618{ 619 return *tp; 620} 621 622// Template with char parameter 623template<class T, char sz> 624class Baz { 625public: 626 int x; 627 T t; 628 T baz (int, T); 629}; 630 631template<class T, char sz> T Baz<T, sz>::baz (int i, T tt) 632{ 633 if (i < sz) 634 return tt; 635 else 636 return 0; 637} 638 639// Template with char * parameter 640template<class T, char * sz> 641class Qux { 642public: 643 int x; 644 T t; 645 T qux (int, T); 646}; 647 648template<class T, char * sz> T Qux<T, sz>::qux (int i, T tt) 649{ 650 if (sz[0] == 'q') 651 return tt; 652 else 653 return 0; 654} 655 656// Template with a function pointer parameter 657template<class T, int (*f)(int) > 658class Qux1 { 659public: 660 int x; 661 T t; 662 T qux (int, T); 663}; 664 665template<class T, int (*f)(int)> T Qux1<T, f>::qux (int i, T tt) 666{ 667 if (f != 0) 668 return tt; 669 else 670 return 0; 671} 672 673// Some functions to provide as arguments to template 674int gf1 (int a) { 675 return a * 2 + 13; 676} 677int gf2 (int a) { 678 return a * 2 + 26; 679} 680 681char string[3]; 682 683 684// Template for nested instantiations 685 686template<class T> 687class Garply { 688public: 689 int x; 690 T t; 691 T garply (int, T); 692}; 693 694template<class T> T Garply<T>::garply (int i, T tt) 695{ 696 if (i > x) 697 return tt; 698 else 699 { 700 x += i; 701 return tt; 702 } 703} 704 705 706int main() 707{ 708 int i; 709#ifdef usestubs 710 set_debug_traps(); 711 breakpoint(); 712#endif 713 i = i + 1; 714 715 // New tests added here 716 717 Foo<int> fint={0,0}; 718 Foo<char> fchar={0,0}; 719 Foo<volatile char *> fvpchar = {0, 0}; 720 721 Bar<int, 33> bint; 722 Bar<int, (4 > 3)> bint2; 723 724 Baz<int, 's'> bazint; 725 Baz<char, 'a'> bazint2; 726 727 Qux<char, string> quxint2; 728 Qux<int, string> quxint; 729 730 Qux1<int, gf1> qux11; 731 732 int x = fint.foo(33, 47); 733 char c = fchar.foo(33, 'x'); 734 volatile char * cp = fvpchar.foo(33, 0); 735 736 int y = dummy<int> (400, 600); 737 738 int z = bint.bar(55, 66); 739 z += bint2.bar(55, 66); 740 741 c = bazint2.baz(4, 'y'); 742 c = quxint2.qux(4, 'z'); 743 744 y = bazint.baz(4,3); 745 y = quxint.qux(4, 22); 746 y += qux11.qux(4, 22); 747 748 y *= gf1(y) - gf2(y); 749 750 Spec<int, char> sic; 751 Spec<int, int *> siip; 752 753 sic.spec ('c'); 754 siip.spec (&x); 755 756 Garply<int> f; 757 Garply<char> fc; 758 f.x = 13; 759 760 Garply<Garply<char> > nf; 761 nf.x = 31; 762 763 x = f.garply (3, 4); 764 765 fc = nf.garply (3, fc); 766 767 y = x + fc.x; 768 769 770 return 0; 771 772} 773 774 775 776 777 778 779 780 781 782 783 784 785 786