]> git.ipfire.org Git - thirdparty/gcc.git/blob - libvtv/testsuite/libvtv.cc/virtfunc-test.cc
Update copyright years.
[thirdparty/gcc.git] / libvtv / testsuite / libvtv.cc / virtfunc-test.cc
1 // { dg-do run }
2
3 /* This test script is part of GDB, the GNU debugger.
4
5 Copyright (C) 1993-2023 Free Software Foundation, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 // Pls try the following program on virtual functions and try to do print on
22 // most of the code in main(). Almost none of them works !
23
24 //
25 // The inheritance structure is:
26 //
27 // V : VA VB
28 // A : (V)
29 // B : A
30 // D : AD (V)
31 // C : (V)
32 // E : B (V) D C
33 //
34
35 class VA
36 {
37 public:
38 int va;
39 };
40
41 class VB
42 {
43 public:
44 int vb;
45 int fvb();
46 virtual int vvb();
47 };
48
49 class V : public VA, public VB
50 {
51 public:
52 int f();
53 virtual int vv();
54 int w;
55 };
56
57 class A : virtual public V
58 {
59 public:
60 virtual int f();
61 private:
62 int a;
63 };
64
65 class B : public A
66 {
67 public:
68 int f();
69 private:
70 int b;
71 };
72
73 class C : public virtual V
74 {
75 public:
76 int c;
77 };
78
79 class AD
80 {
81 public:
82 virtual int vg() = 0;
83 };
84
85 class D : public AD, virtual public V
86 {
87 public:
88 static void s();
89 virtual int vg();
90 virtual int vd();
91 int fd();
92 int d;
93 };
94
95 class E : public B, virtual public V, public D, public C
96 {
97 public:
98 int f();
99 int vg();
100 int vv();
101 int e;
102 };
103
104 D dd;
105 D* ppd = &dd;
106 AD* pAd = &dd;
107
108 A a;
109 B b;
110 C c;
111 D d;
112 E e;
113 V v;
114 VB vb;
115
116
117 A* pAa = &a;
118 A* pAe = &e;
119
120 B* pBe = &e;
121
122 D* pDd = &d;
123 D* pDe = &e;
124
125 V* pVa = &a;
126 V* pVv = &v;
127 V* pVe = &e;
128 V* pVd = &d;
129
130 AD* pADe = &e;
131
132 E* pEe = &e;
133
134 VB* pVB = &vb;
135
136 void init()
137 {
138 a.vb = 1;
139 b.vb = 2;
140 c.vb = 3;
141 d.vb = 4;
142 e.vb = 5;
143 v.vb = 6;
144 vb.vb = 7;
145
146 d.d = 1;
147 e.d = 2;
148 }
149
150 extern "C" int printf(const char *, ...);
151
152 int all_count = 0;
153 int failed_count = 0;
154
155 #define TEST(EXPR, EXPECTED) \
156 ret = EXPR; \
157 if (ret != EXPECTED) {\
158 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
159 failed_count++; } \
160 all_count++;
161
162 int ret;
163
164 void test_calls()
165 {
166 TEST(pAe->f(), 20);
167 TEST(pAa->f(), 1);
168
169 TEST(pDe->vg(), 202);
170 TEST(pADe->vg(), 202);
171 TEST(pDd->vg(), 101);
172
173 TEST(pEe->vvb(), 411);
174
175 TEST(pVB->vvb(), 407);
176
177 TEST(pBe->vvb(), 411);
178 TEST(pDe->vvb(), 411);
179
180 TEST(pEe->vd(), 282);
181 TEST(pEe->fvb(), 311);
182
183 TEST(pEe->D::vg(), 102);
184 printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
185 }
186 #ifdef usestubs
187 extern "C" {
188 void set_debug_traps();
189 void breakpoint();
190 };
191 #endif
192
193 int main()
194 {
195 #ifdef usestubs
196 set_debug_traps();
197 breakpoint();
198 #endif
199 init();
200
201 e.w = 7;
202 e.vb = 11;
203
204 test_calls();
205 return 0;
206
207 }
208
209 int A::f() {return 1;}
210 int B::f() {return 2;}
211 void D::s() {}
212 int E::f() {return 20;}
213 int D::vg() {return 100+d;}
214 int E::vg() {return 200+d;}
215 int V::f() {return 600+w;}
216 int V::vv() {return 400+w;}
217 int E::vv() {return 450+w;}
218 int D::fd() {return 250+d;}
219 int D::vd() {return 280+d;}
220 int VB::fvb() {return 300+vb;}
221 int VB::vvb() {return 400+vb;}