* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / smoke.cc
CommitLineData
7e745333
DT
1// Test various -*- C++ -*- things.
2
3typedef struct fleep fleep;
4struct fleep { int a; } s;
5
6// ====================== simple class structures =======================
7
8struct default_public_struct {
9 // defaults to public:
10 int a;
11 int b;
12};
13
14struct explicit_public_struct {
15 public:
16 int a;
17 int b;
18};
19
20struct protected_struct {
21 protected:
22 int a;
23 int b;
24};
25
26struct private_struct {
27 private:
28 int a;
29 int b;
30};
31
32struct mixed_protection_struct {
33 public:
34 int a;
35 int b;
36 private:
37 int c;
38 int d;
39 protected:
40 int e;
41 int f;
42 public:
43 int g;
44 private:
45 int h;
46 protected:
47 int i;
48};
49
50class public_class {
51 public:
52 int a;
53 int b;
54};
55
56class protected_class {
57 protected:
58 int a;
59 int b;
60};
61
62class default_private_class {
63 // defaults to private:
64 int a;
65 int b;
66};
67
68class explicit_private_class {
69 private:
70 int a;
71 int b;
72};
73
74class mixed_protection_class {
75 public:
76 int a;
77 int b;
78 private:
79 int c;
80 int d;
81 protected:
82 int e;
83 int f;
84 public:
85 int g;
86 private:
87 int h;
88 protected:
89 int i;
90};
91
92// ========================= simple inheritance ==========================
93
94class A {
95 public:
96 int a;
97 int x;
98};
99
100A g_A;
101
102class B : public A {
103 public:
104 int b;
105 int x;
106};
107
108B g_B;
109
110class C : public A {
111 public:
112 int c;
113 int x;
114};
115
116C g_C;
117
118class D : public B, public C {
119 public:
120 int d;
121 int x;
122};
123
124D g_D;
125
126class E : public D {
127 public:
128 int e;
129 int x;
130};
131
132E g_E;
133
134class class_with_anon_union
135{
136 public:
137 int one;
138 union
139 {
140 int a;
141 long b;
142 };
143};
144
145class_with_anon_union g_anon_union;
146
147void inheritance2 (void)
148{
149}
150
151void inheritance1 (void)
152{
153 int ival;
154 int *intp;
155
156 // {A::a, A::x}
157
158 g_A.A::a = 1;
159 g_A.A::x = 2;
160
161 // {{A::a,A::x},B::b,B::x}
162
163 g_B.A::a = 3;
164 g_B.A::x = 4;
165 g_B.B::b = 5;
166 g_B.B::x = 6;
167
168 // {{A::a,A::x},C::c,C::x}
169
170 g_C.A::a = 7;
171 g_C.A::x = 8;
172 g_C.C::c = 9;
173 g_C.C::x = 10;
174
175 // {{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}
176
177 // The following initialization code is non-portable, but allows us
178 // to initialize all members of g_D until we can fill in the missing
179 // initialization code with legal C++ code.
180
181 for (intp = (int *) &g_D, ival = 11;
182 intp < ((int *) &g_D + sizeof (g_D) / sizeof (int));
183 intp++, ival++)
184 {
185 *intp = ival;
186 }
187
188 // Overlay the nonportable initialization with legal initialization.
189
190 // ????? = 11; (g_D.A::a = 11; is ambiguous)
191 // ????? = 12; (g_D.A::x = 12; is ambiguous)
192 g_D.B::b = 13;
193 g_D.B::x = 14;
194 // ????? = 15;
195 // ????? = 16;
196 g_D.C::c = 17;
197 g_D.C::x = 18;
198 g_D.D::d = 19;
199 g_D.D::x = 20;
200
201
202 // {{{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}},E::e,E::x}
203
204 // The following initialization code is non-portable, but allows us
205 // to initialize all members of g_D until we can fill in the missing
206 // initialization code with legal C++ code.
207
208 for (intp = (int *) &g_E, ival = 21;
209 intp < ((int *) &g_E + sizeof (g_E) / sizeof (int));
210 intp++, ival++)
211 {
212 *intp = ival;
213 }
214
215 // Overlay the nonportable initialization with legal initialization.
216
217 // ????? = 21; (g_E.A::a = 21; is ambiguous)
218 // ????? = 22; (g_E.A::x = 22; is ambiguous)
219 g_E.B::b = 23;
220 g_E.B::x = 24;
221 // ????? = 25;
222 // ????? = 26;
223 g_E.C::c = 27;
224 g_E.C::x = 28;
225 g_E.D::d = 29;
226 g_E.D::x = 30;
227 g_E.E::e = 31;
228 g_E.E::x = 32;
229
230 g_anon_union.one = 1;
231 g_anon_union.a = 2;
232
233 inheritance2 ();
234}
235
236// ======================== virtual base classes=========================
237
238class vA {
239 public:
240 int va;
241 int vx;
242};
243
244vA g_vA;
245
246class vB : public virtual vA {
247 public:
248 int vb;
249 int vx;
250};
251
252vB g_vB;
253
254class vC : public virtual vA {
255 public:
256 int vc;
257 int vx;
258};
259
260vC g_vC;
261
262class vD : public virtual vB, public virtual vC {
263 public:
264 int vd;
265 int vx;
266};
267
268vD g_vD;
269
270class vE : public virtual vD {
271 public:
272 int ve;
273 int vx;
274};
275
276vE g_vE;
277
278void inheritance4 (void)
279{
280}
281
282void inheritance3 (void)
283{
284 int ival;
285 int *intp;
286
287 // {vA::va, vA::vx}
288
289 g_vA.vA::va = 1;
290 g_vA.vA::vx = 2;
291
292 // {{vA::va, vA::vx}, vB::vb, vB::vx}
293
294 g_vB.vA::va = 3;
295 g_vB.vA::vx = 4;
296 g_vB.vB::vb = 5;
297 g_vB.vB::vx = 6;
298
299 // {{vA::va, vA::vx}, vC::vc, vC::vx}
300
301 g_vC.vA::va = 7;
302 g_vC.vA::vx = 8;
303 g_vC.vC::vc = 9;
304 g_vC.vC::vx = 10;
305
306 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
307
308 g_vD.vA::va = 11;
309 g_vD.vA::vx = 12;
310 g_vD.vB::vb = 13;
311 g_vD.vB::vx = 14;
312 g_vD.vC::vc = 15;
313 g_vD.vC::vx = 16;
314 g_vD.vD::vd = 17;
315 g_vD.vD::vx = 18;
316
317
318 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
319
320 g_vD.vA::va = 19;
321 g_vD.vA::vx = 20;
322 g_vD.vB::vb = 21;
323 g_vD.vB::vx = 22;
324 g_vD.vC::vc = 23;
325 g_vD.vC::vx = 24;
326 g_vD.vD::vd = 25;
327 g_vD.vD::vx = 26;
328 g_vE.vE::ve = 27;
329 g_vE.vE::vx = 28;
330
331 inheritance4 ();
332}
333
334// ======================================================================
335
336class Base1 {
337 public:
338 int x;
339 Base1(int i) { x = i; }
340};
341
342class Foo
343{
344 public:
345 int x;
346 int y;
347 static int st;
348 Foo (int i, int j) { x = i; y = j; }
349 int operator! ();
350 operator int ();
351 int times (int y);
352};
353
354class Bar : public Base1, public Foo {
355 public:
356 int z;
357 Bar (int i, int j, int k) : Base1 (10*k), Foo (i, j) { z = k; }
358};
359
360int Foo::operator! () { return !x; }
361
362int Foo::times (int y) { return x * y; }
363
364int Foo::st = 100;
365
366Foo::operator int() { return x; }
367
368Foo foo(10, 11);
369Bar bar(20, 21, 22);
370
371class Contains_static_instance
372{
373 public:
374 int x;
375 int y;
376 Contains_static_instance (int i, int j) { x = i; y = j; }
377 static Contains_static_instance null;
378};
379
380Contains_static_instance Contains_static_instance::null(0,0);
381Contains_static_instance csi(10,20);
382
383class Contains_nested_static_instance
384{
385 public:
386 class Nested
387 {
388 public:
389 Nested(int i) : z(i) {}
390 int z;
391 static Contains_nested_static_instance xx;
392 };
393
394 Contains_nested_static_instance(int i, int j) : x(i), y(j) {}
395
396 int x;
397 int y;
398
399 static Contains_nested_static_instance null;
400 static Nested yy;
401};
402
403Contains_nested_static_instance Contains_nested_static_instance::null(0, 0);
404Contains_nested_static_instance::Nested Contains_nested_static_instance::yy(5);
405Contains_nested_static_instance
406 Contains_nested_static_instance::Nested::xx(1,2);
407Contains_nested_static_instance cnsi(30,40);
408
409typedef struct {
410 int one;
411 int two;
412} tagless_struct;
413tagless_struct v_tagless;
414
415/* Try to get the compiler to allocate a class in a register. */
416class small {
417 public:
418 int x;
419 int method ();
420};
421int small::method ()
422{
423 return x + 5;
424}
425void marker_reg1 () {}
426
427int
428register_class ()
429{
430 /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
431 might put this variable in a register. This is a lose, though, because
432 it means that GDB can't call any methods for that variable. */
433 register small v;
434
435 int i;
436
437 /* Perform a computation sufficiently complicated that optimizing compilers
438 won't optimized out the variable. If some compiler constant-folds this
439 whole loop, maybe using a parameter to this function here would help. */
440 v.x = 0;
441 for (i = 0; i < 13; ++i)
442 v.x += i;
443 --v.x; /* v.x is now 77 */
444 marker_reg1 ();
445 return v.x + 5;
446}
447
448int
449main()
450{
451#ifdef usestubs
452 set_debug_traps();
453 breakpoint();
454#endif
455 inheritance1 ();
456 inheritance3 ();
457 register_class ();
458
459 /* FIXME: pmi gets optimized out. Need to do some more computation with
460 it or something. (No one notices, because the test is xfail'd anyway,
461 but that probably won't always be true...). */
462 int Foo::* pmi = &Foo::y;
463
464 /* Make sure the AIX linker doesn't remove the variable. */
465 v_tagless.one = 5;
466
467 return foo.*pmi;
468}
469
470/* Create an instance for some classes, otherwise they get optimized away. */
471default_public_struct default_public_s;
472explicit_public_struct explicit_public_s;
473protected_struct protected_s;
474private_struct private_s;
475mixed_protection_struct mixed_protection_s;
476public_class public_c;
477protected_class protected_c;
478default_private_class default_private_c;
479explicit_private_class explicit_private_c;
480mixed_protection_class mixed_protection_c;
This page took 0.078664 seconds and 4 git commands to generate.