gdb: Fix scrolling in TUI
[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
152fcc9c
TT
56 char av = 'a';
57 char *a = &av; // pointer to..
7062b0a0
SW
58 B *bp;
59 foo1_1 (a); // ..pointer
60 foo1_2 (a); // ..array
61 foo1_3 ((int*)a); // ..pointer of wrong type
62 foo1_3 ((int*)bp); // ..pointer of wrong type
63 foo1_4 (bp); // ..ancestor pointer
64 foo1_5 (bp); // ..void pointer
026ffab7
SW
65 foo1_6 ((void**)bp); // ..void pointer pointer
66 foo1_7 (bp); // ..boolean
67 foo1_8 ((long)bp); // ..long int
7062b0a0
SW
68
69 char **b; // pointer pointer to..
70 char ba[1][1];
71 foo1_5 (b); // ..void pointer
72 foo2_1 (b); // ..pointer pointer
73 foo2_2 (ba); // ..array of arrays
74 foo2_3 (b); // ..array of pointers
75 foo2_4 ((int**)b); // ..array of wrong pointers
6501c2fc 76
5b4f6e25
KS
77 // X to boolean conversions allowed by the standard
78 int integer = 0;
79 long long_int = 1;
80 float fp = 1.0;
81 double dp = 1.0;
82 foo1_7 (integer); // integer to boolean
83 foo1_7 (long_int); // long to boolean
84 foo1_7 (*a); // char to boolean
85 foo1_7 (MY_A); // unscoped enum to boolean
ea3a9873
KS
86 /* converts.exp tests the next statement directly. It is not compiled
87 here for verification because older versions of GCC (~4.1) fail to
88 compile it:
89
90 warning: the address of 'int foo1_7(bool)' will always evaluate as true
91
5b4f6e25 92 foo1_7 (&foo1_7); // pointer to boolean
ea3a9873
KS
93 */
94
5b4f6e25
KS
95 foo1_7 (&A::member_); // pointer to member to boolean
96 foo1_7 (a); // pointer to boolean
97 foo1_7 (fp); // float to boolean
98 foo1_7 (dp); // double to boolean
99
6501c2fc
KS
100 foo3_1 (0, 0);
101 foo3_2 (0, static_cast<char const**> (0));
102 foo3_2 (0, 0);
103
a451cb65
KS
104 foo1_type_check (a);
105 foo2_type_check (a, a);
106 foo3_type_check (a, a, a);
107
7062b0a0
SW
108 return 0; // end of main
109}
This page took 1.045639 seconds and 4 git commands to generate.