1 // Test various -*- C++ -*- things.
3 typedef struct fleep fleep
;
4 struct fleep
{ int a
; } s
;
6 // ====================== simple class structures =======================
8 struct default_public_struct
{
14 struct explicit_public_struct
{
20 struct protected_struct
{
26 struct private_struct
{
32 struct mixed_protection_struct
{
56 class protected_class
{
62 class default_private_class
{
63 // defaults to private:
68 class explicit_private_class
{
74 class mixed_protection_class
{
92 // ========================= simple inheritance ==========================
118 class D
: public B
, public C
{
134 class class_with_anon_union
145 class_with_anon_union g_anon_union
;
147 void inheritance2 (void)
151 void inheritance1 (void)
161 // {{A::a,A::x},B::b,B::x}
168 // {{A::a,A::x},C::c,C::x}
175 // {{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}
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.
181 for (intp
= (int *) &g_D
, ival
= 11;
182 intp
< ((int *) &g_D
+ sizeof (g_D
) / sizeof (int));
188 // Overlay the nonportable initialization with legal initialization.
190 // ????? = 11; (g_D.A::a = 11; is ambiguous)
191 // ????? = 12; (g_D.A::x = 12; is ambiguous)
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}
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.
208 for (intp
= (int *) &g_E
, ival
= 21;
209 intp
< ((int *) &g_E
+ sizeof (g_E
) / sizeof (int));
215 // Overlay the nonportable initialization with legal initialization.
217 // ????? = 21; (g_E.A::a = 21; is ambiguous)
218 // ????? = 22; (g_E.A::x = 22; is ambiguous)
230 g_anon_union
.one
= 1;
236 // ======================== virtual base classes=========================
246 class vB
: public virtual vA
{
254 class vC
: public virtual vA
{
262 class vD
: public virtual vB
, public virtual vC
{
270 class vE
: public virtual vD
{
278 void inheritance4 (void)
282 void inheritance3 (void)
292 // {{vA::va, vA::vx}, vB::vb, vB::vx}
299 // {{vA::va, vA::vx}, vC::vc, vC::vx}
306 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
318 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
334 // ======================================================================
339 Base1(int i
) { x
= i
; }
348 Foo (int i
, int j
) { x
= i
; y
= j
; }
354 class Bar
: public Base1
, public Foo
{
357 Bar (int i
, int j
, int k
) : Base1 (10*k
), Foo (i
, j
) { z
= k
; }
360 int Foo::operator! () { return !x
; }
362 int Foo::times (int y
) { return x
* y
; }
366 Foo::operator int() { return x
; }
371 class Contains_static_instance
376 Contains_static_instance (int i
, int j
) { x
= i
; y
= j
; }
377 static Contains_static_instance null
;
380 Contains_static_instance
Contains_static_instance::null(0,0);
381 Contains_static_instance
csi(10,20);
383 class Contains_nested_static_instance
389 Nested(int i
) : z(i
) {}
391 static Contains_nested_static_instance xx
;
394 Contains_nested_static_instance(int i
, int j
) : x(i
), y(j
) {}
399 static Contains_nested_static_instance null
;
403 Contains_nested_static_instance
Contains_nested_static_instance::null(0, 0);
404 Contains_nested_static_instance::Nested
Contains_nested_static_instance::yy(5);
405 Contains_nested_static_instance
406 Contains_nested_static_instance::Nested::xx(1,2);
407 Contains_nested_static_instance
cnsi(30,40);
413 tagless_struct v_tagless
;
415 /* Try to get the compiler to allocate a class in a register. */
425 void marker_reg1 () {}
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. */
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. */
441 for (i
= 0; i
< 13; ++i
)
443 --v
.x
; /* v.x is now 77 */
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
;
464 /* Make sure the AIX linker doesn't remove the variable. */
470 /* Create an instance for some classes, otherwise they get optimized away. */
471 default_public_struct default_public_s
;
472 explicit_public_struct explicit_public_s
;
473 protected_struct protected_s
;
474 private_struct private_s
;
475 mixed_protection_struct mixed_protection_s
;
476 public_class public_c
;
477 protected_class protected_c
;
478 default_private_class default_private_c
;
479 explicit_private_class explicit_private_c
;
480 mixed_protection_class mixed_protection_c
;