gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / converts.cc
CommitLineData
5b4f6e25
KS
1class A
2{
3public:
4 A() : member_ (0) {};
5 int member_;
6};
7062b0a0
SW
7class B : public A {};
8
9typedef A TA1;
10typedef A TA2;
11typedef TA2 TA3;
12
5b4f6e25
KS
13enum my_enum {MY_A, MY_B, MY_C, MY_D};
14
666b578b
JK
15/* Without this variable older 'enum my_enum' incl. its 'MY_A' would be omitted
16 by older versions of GCC (~4.1) failing the testcase using it below. */
17enum my_enum my_enum_var;
18
7062b0a0
SW
19int foo0_1 (TA1) { return 1; }
20int foo0_2 (TA3) { return 2; }
21int foo0_3 (A***) { return 3; }
22
23int foo1_1 (char *) {return 11;}
24int foo1_2 (char[]) {return 12;}
25int foo1_3 (int*) {return 13;}
26int foo1_4 (A*) {return 14;}
27int foo1_5 (void*) {return 15;}
026ffab7
SW
28int foo1_6 (void**) {return 16;}
29int foo1_7 (bool) {return 17;}
30int foo1_8 (long) {return 18;}
7062b0a0
SW
31
32int foo2_1 (char** ) {return 21;}
33int foo2_2 (char[][1]) {return 22;}
34int foo2_3 (char *[]) {return 23;}
35int foo2_4 (int *[]) {return 24;}
36
6501c2fc
KS
37int foo3_1 (int a, const char **b) { return 31; }
38int foo3_2 (int a, int b) { return 32; }
39int foo3_2 (int a, const char **b) { return 320; }
40
a451cb65
KS
41int foo1_type_check (char *a) { return 1000; }
42int foo2_type_check (char *a, char *b) { return 1001; }
43int foo3_type_check (char *a, char *b, char *c) { return 1002; }
44
7062b0a0
SW
45int main()
46{
47
48 TA2 ta; // typedef to..
49 foo0_1 (ta); // ..another typedef
50 foo0_2 (ta); // ..typedef of a typedef
51
52 B*** bppp; // Pointer-to-pointer-to-pointer-to-derived..
53//foo0_3(bppp); // Pointer-to-pointer-to-pointer base.
54 foo0_3((A***)bppp); // to ensure that the function is emitted.
55
56 char *a; // pointer to..
57 B *bp;
58 foo1_1 (a); // ..pointer
59 foo1_2 (a); // ..array
60 foo1_3 ((int*)a); // ..pointer of wrong type
61 foo1_3 ((int*)bp); // ..pointer of wrong type
62 foo1_4 (bp); // ..ancestor pointer
63 foo1_5 (bp); // ..void pointer
026ffab7
SW
64 foo1_6 ((void**)bp); // ..void pointer pointer
65 foo1_7 (bp); // ..boolean
66 foo1_8 ((long)bp); // ..long int
7062b0a0
SW
67
68 char **b; // pointer pointer to..
69 char ba[1][1];
70 foo1_5 (b); // ..void pointer
71 foo2_1 (b); // ..pointer pointer
72 foo2_2 (ba); // ..array of arrays
73 foo2_3 (b); // ..array of pointers
74 foo2_4 ((int**)b); // ..array of wrong pointers
6501c2fc 75
5b4f6e25
KS
76 // X to boolean conversions allowed by the standard
77 int integer = 0;
78 long long_int = 1;
79 float fp = 1.0;
80 double dp = 1.0;
81 foo1_7 (integer); // integer to boolean
82 foo1_7 (long_int); // long to boolean
83 foo1_7 (*a); // char to boolean
84 foo1_7 (MY_A); // unscoped enum to boolean
ea3a9873
KS
85 /* converts.exp tests the next statement directly. It is not compiled
86 here for verification because older versions of GCC (~4.1) fail to
87 compile it:
88
89 warning: the address of 'int foo1_7(bool)' will always evaluate as true
90
5b4f6e25 91 foo1_7 (&foo1_7); // pointer to boolean
ea3a9873
KS
92 */
93
5b4f6e25
KS
94 foo1_7 (&A::member_); // pointer to member to boolean
95 foo1_7 (a); // pointer to boolean
96 foo1_7 (fp); // float to boolean
97 foo1_7 (dp); // double to boolean
98
6501c2fc
KS
99 foo3_1 (0, 0);
100 foo3_2 (0, static_cast<char const**> (0));
101 foo3_2 (0, 0);
102
a451cb65
KS
103 foo1_type_check (a);
104 foo2_type_check (a, a);
105 foo3_type_check (a, a, a);
106
7062b0a0
SW
107 return 0; // end of main
108}
This page took 0.253231 seconds and 4 git commands to generate.