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 class const_vol_method_class
{
96 int foo (int &) const;
97 int bar (int &) volatile;
98 int baz (int &) const volatile;
101 int const_vol_method_class::foo (int & ir
) const
105 int const_vol_method_class::bar (int & ir
) volatile
109 int const_vol_method_class::baz (int & ir
) const volatile
114 // ========================= simple inheritance ==========================
140 class D
: public B
, public C
{
156 class class_with_anon_union
167 class_with_anon_union g_anon_union
;
169 void inheritance2 (void)
173 void inheritance1 (void)
183 // {{A::a,A::x},B::b,B::x}
190 // {{A::a,A::x},C::c,C::x}
197 // {{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}
199 // The following initialization code is non-portable, but allows us
200 // to initialize all members of g_D until we can fill in the missing
201 // initialization code with legal C++ code.
203 for (intp
= (int *) &g_D
, ival
= 11;
204 intp
< ((int *) &g_D
+ sizeof (g_D
) / sizeof (int));
210 // Overlay the nonportable initialization with legal initialization.
212 // ????? = 11; (g_D.A::a = 11; is ambiguous)
213 // ????? = 12; (g_D.A::x = 12; is ambiguous)
224 // {{{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}},E::e,E::x}
226 // The following initialization code is non-portable, but allows us
227 // to initialize all members of g_D until we can fill in the missing
228 // initialization code with legal C++ code.
230 for (intp
= (int *) &g_E
, ival
= 21;
231 intp
< ((int *) &g_E
+ sizeof (g_E
) / sizeof (int));
237 // Overlay the nonportable initialization with legal initialization.
239 // ????? = 21; (g_E.A::a = 21; is ambiguous)
240 // ????? = 22; (g_E.A::x = 22; is ambiguous)
252 g_anon_union
.one
= 1;
258 // ======================== virtual base classes=========================
268 class vB
: public virtual vA
{
276 class vC
: public virtual vA
{
284 class vD
: public virtual vB
, public virtual vC
{
292 class vE
: public virtual vD
{
300 void inheritance4 (void)
304 void inheritance3 (void)
314 // {{vA::va, vA::vx}, vB::vb, vB::vx}
321 // {{vA::va, vA::vx}, vC::vc, vC::vx}
328 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
340 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
356 // ======================================================================
361 Base1(int i
) { x
= i
; }
370 Foo (int i
, int j
) { x
= i
; y
= j
; }
376 class Bar
: public Base1
, public Foo
{
379 Bar (int i
, int j
, int k
) : Base1 (10*k
), Foo (i
, j
) { z
= k
; }
382 class ClassWithEnum
{
384 enum PrivEnum
{ red
, green
, blue
, yellow
= 42 };
389 int Foo::operator! () { return !x
; }
391 int Foo::times (int y
) { return x
* y
; }
395 Foo::operator int() { return x
; }
400 class Contains_static_instance
405 Contains_static_instance (int i
, int j
) { x
= i
; y
= j
; }
406 static Contains_static_instance null
;
409 Contains_static_instance
Contains_static_instance::null(0,0);
410 Contains_static_instance
csi(10,20);
412 class Contains_nested_static_instance
418 Nested(int i
) : z(i
) {}
420 static Contains_nested_static_instance xx
;
423 Contains_nested_static_instance(int i
, int j
) : x(i
), y(j
) {}
428 static Contains_nested_static_instance null
;
432 Contains_nested_static_instance
Contains_nested_static_instance::null(0, 0);
433 Contains_nested_static_instance::Nested
Contains_nested_static_instance::yy(5);
434 Contains_nested_static_instance
435 Contains_nested_static_instance::Nested::xx(1,2);
436 Contains_nested_static_instance
cnsi(30,40);
442 tagless_struct v_tagless
;
444 /* Try to get the compiler to allocate a class in a register. */
457 void marker_reg1 () {}
462 /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
463 might put this variable in a register. This is a lose, though, because
464 it means that GDB can't call any methods for that variable. */
469 /* Perform a computation sufficiently complicated that optimizing compilers
470 won't optimized out the variable. If some compiler constant-folds this
471 whole loop, maybe using a parameter to this function here would help. */
473 for (i
= 0; i
< 13; ++i
)
475 --v
.x
; /* v.x is now 77 */
491 /* FIXME: pmi gets optimized out. Need to do some more computation with
492 it or something. (No one notices, because the test is xfail'd anyway,
493 but that probably won't always be true...). */
494 int Foo::* pmi
= &Foo::y
;
496 /* Make sure the AIX linker doesn't remove the variable. */
499 /* Class with enumeration inside it */
500 ClassWithEnum obj_with_enum
;
501 obj_with_enum
.priv_enum
= ClassWithEnum::red
;
503 obj_with_enum
.priv_enum
= ClassWithEnum::green
;
508 /* Create an instance for some classes, otherwise they get optimized away. */
510 default_public_struct default_public_s
;
511 explicit_public_struct explicit_public_s
;
512 protected_struct protected_s
;
513 private_struct private_s
;
514 mixed_protection_struct mixed_protection_s
;
515 public_class public_c
;
516 protected_class protected_c
;
517 default_private_class default_private_c
;
518 explicit_private_class explicit_private_c
;
519 mixed_protection_class mixed_protection_c
;