Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.benjamin/typeid01.C

raw
1 // { dg-do run }
2 // 980617 bkoz
3 // typeid for local types
4 // typeid bool vs int and enum vs int
5
6 #include <typeinfo>
7 #ifdef DEBUG_ASSERT
8 #include <assert.h>
9 #endif
10
11 // 4: local class in non-main function
12
13 void test1 (void) {
14 bool class_p = false;
15 class X2 {
16 private:
17 unsigned int counter;
18 public:
19 X2 (unsigned int i = 35): counter(i) {}
20 ~X2(){}
21 unsigned int ret_counter() {return counter;}
22 };
23 X2 obj_1;
24 class_p = typeid(X2) == typeid(obj_1);
25 }
26
27 int main ()
28 {
29 // 1: simple
30 #if 1
31 bool enum_p = false;
32 enum E { A, B, C };
33 enum_p = typeid(A) == typeid(E);
34 #ifdef DEBUG_ASSERT
35 assert (enum_p);
36 #endif
37 #endif
38
39 // 2: complex
40 #if 0
41 bool enum2_p = false;
42 bool int_p = false;
43 bool bool_p = false;
44 enum E2 { A2, B2};
45 enum2_p = typeid(A2) == typeid(E2);
46 int_p = typeid(int) == typeid(E2);
47 bool_p = typeid(bool) == typeid(E2);
48 #ifdef DEBUG_ASSERT
49 assert (enum2_p);
50 assert (!int_p);
51 assert (!bool_p);
52 #endif
53 #endif
54
55 // 3: local class
56 bool class_p = false;
57 class X {
58 private:
59 unsigned int counter;
60 public:
61 X (unsigned int i = 35): counter(i) {}
62 ~X(){}
63 unsigned int ret_counter() {return counter;}
64 };
65 X obj_1;
66 class_p = typeid(X) == typeid(obj_1);
67
68 // 4: local class in function
69 test1();
70
71 return 0;
72 }