1 // test of rtti of non-class types 2 // Special g++ Options: -frtti 3 4 #include <typeinfo> 5 6 extern "C" { 7 int printf(const char *, ...); 8 void exit(int); 9 } 10 11 int i; 12 short s; 13 char c; 14 long l; 15 16 unsigned int ui; 17 unsigned short us; 18 unsigned char uc; 19 unsigned long ul; 20 21 float f; 22 double d; 23 24 int& ri = i; 25 const volatile int cvi = 10; 26 volatile const int vci = 20; 27 const int ci = 100; 28 29 int *pi; 30 int ai[10]; 31 32 enum color { red, blue, green, yellow}; 33 34 int (*fp)(); 35 int (*gp)(); 36 int (*hp)(int); 37 38 class XX { 39 public: 40 int xxi; 41 float xxf; xxf1()42 int xxf1 () { return 0; }; xxf2(int k)43 int xxf2 (int k) { return 0; }; 44 }; 45 46 class YY { 47 public: 48 int yyi; 49 double yyd; yyf1(float f)50 int yyf1 (float f) { return 0; }; yyf2()51 double yyf2 () {return yyd;}; 52 }; 53 54 int XX::*ptmd1; 55 int XX::*ptmd2; 56 float XX::*ptmd3; 57 int YY::*ptmd4; 58 59 int (XX::*ptmf1) (); 60 int (XX::*ptmf2) (); 61 int (XX::*ptmf3) (int); 62 int (YY::*ptmf4) (); 63 func1()64int func1 () 65 { return 0;} 66 func2()67int func2 () 68 { return 1;} 69 func3(int i)70int func3 (int i) 71 { return i;} 72 func4()73short func4 () 74 { return 99;} 75 error(int i)76void error (int i) 77 { 78 exit(i); 79 } 80 main()81int main () 82 { 83 if (typeid(i) != typeid(int)) error(1); 84 if (typeid(s) != typeid(short)) error(2); 85 if (typeid(c) != typeid(char)) error(3); 86 if (typeid(l) != typeid(long)) error(4); 87 if (typeid(ui) != typeid(unsigned int)) error(5); 88 if (typeid(us) != typeid(unsigned short)) error(6); 89 if (typeid(uc) != typeid(unsigned char)) error(7); 90 if (typeid(ul) != typeid(unsigned long)) error(8); 91 if (typeid(f) != typeid(float)) error(9); 92 if (typeid(d) != typeid(double)) error(10); 93 94 if (typeid(*pi) != typeid(int)) error(51); 95 if (typeid(pi) == typeid(ai)) error(52); 96 if (typeid(ri) != typeid(i)) error(53); 97 if (typeid(cvi) != typeid(vci)) error (54); 98 if (typeid(vci) != typeid(i)) error(55); 99 if (typeid(ci) != typeid(cvi)) error (56); 100 if (typeid(ci) != typeid(const int)) error(57); 101 102 if (typeid(func1) != typeid(func2)) error (81); 103 if (typeid(func2) == typeid(func3)) error (82); 104 if (typeid(func1) == typeid(func4)) error (83); 105 if (typeid(func3) == typeid(func4)) error (84); 106 107 if (typeid(red) != typeid(color)) error (101); 108 if (typeid(green) != typeid(blue)) error (102); 109 110 if (typeid(fp) != typeid(gp)) error (103); 111 if (typeid(gp) == typeid(hp)) error (104); 112 113 if (typeid(ptmd1) != typeid(ptmd2)) error (105); 114 if (typeid(ptmd1) == typeid(ptmd3)) error (106); 115 if (typeid(ptmd2) == typeid(ptmd4)) error (107); 116 117 if (typeid(ptmf1) != typeid(ptmf2)) error (108); 118 if (typeid(ptmf2) == typeid(ptmf3)) error (109); 119 if (typeid(ptmf1) == typeid(ptmf4)) error (110); 120 return 0; 121 } 122