1 // Test various -*- C++ -*- things.
3 // ====================== basic C++ types =======================
7 typedef struct fleep fleep
;
8 struct fleep
{ int a
; } s
;
10 // ====================== simple class structures =======================
12 struct default_public_struct
{
13 // defaults to public:
18 struct explicit_public_struct
{
24 struct protected_struct
{
30 struct private_struct
{
36 struct mixed_protection_struct
{
60 class protected_class
{
66 class default_private_class
{
67 // defaults to private:
72 class explicit_private_class
{
78 class mixed_protection_class
{
96 class const_vol_method_class
{
100 int foo (int &) const;
101 int bar (int &) volatile;
102 int baz (int &) const volatile;
105 int const_vol_method_class::foo (int & ir
) const
109 int const_vol_method_class::bar (int & ir
) volatile
113 int const_vol_method_class::baz (int & ir
) const volatile
118 // ========================= simple inheritance ==========================
144 class D
: public B
, public C
{
160 class class_with_anon_union
171 class_with_anon_union g_anon_union
;
173 void inheritance2 (void)
177 void inheritance1 (void)
187 // {{A::a,A::x},B::b,B::x}
194 // {{A::a,A::x},C::c,C::x}
201 // {{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}
203 // The following initialization code is non-portable, but allows us
204 // to initialize all members of g_D until we can fill in the missing
205 // initialization code with legal C++ code.
207 for (intp
= (int *) &g_D
, ival
= 11;
208 intp
< ((int *) &g_D
+ sizeof (g_D
) / sizeof (int));
214 // Overlay the nonportable initialization with legal initialization.
216 // ????? = 11; (g_D.A::a = 11; is ambiguous)
217 // ????? = 12; (g_D.A::x = 12; is ambiguous)
228 // {{{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}},E::e,E::x}
230 // The following initialization code is non-portable, but allows us
231 // to initialize all members of g_D until we can fill in the missing
232 // initialization code with legal C++ code.
234 for (intp
= (int *) &g_E
, ival
= 21;
235 intp
< ((int *) &g_E
+ sizeof (g_E
) / sizeof (int));
241 // Overlay the nonportable initialization with legal initialization.
243 // ????? = 21; (g_E.A::a = 21; is ambiguous)
244 // ????? = 22; (g_E.A::x = 22; is ambiguous)
256 g_anon_union
.one
= 1;
262 // ======================== virtual base classes=========================
272 class vB
: public virtual vA
{
280 class vC
: public virtual vA
{
288 class vD
: public virtual vB
, public virtual vC
{
296 class vE
: public virtual vD
{
304 void inheritance4 (void)
308 void inheritance3 (void)
318 // {{vA::va, vA::vx}, vB::vb, vB::vx}
325 // {{vA::va, vA::vx}, vC::vc, vC::vx}
332 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
344 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
360 // ======================================================================
365 Base1(int i
) { x
= i
; }
374 Foo (int i
, int j
) { x
= i
; y
= j
; }
380 class Bar
: public Base1
, public Foo
{
383 Bar (int i
, int j
, int k
) : Base1 (10*k
), Foo (i
, j
) { z
= k
; }
386 class ClassWithEnum
{
388 enum PrivEnum
{ red
, green
, blue
, yellow
= 42 };
393 int Foo::operator! () { return !x
; }
395 int Foo::times (int y
) { return x
* y
; }
399 Foo::operator int() { return x
; }
404 class Contains_static_instance
409 Contains_static_instance (int i
, int j
) { x
= i
; y
= j
; }
410 static Contains_static_instance null
;
413 Contains_static_instance
Contains_static_instance::null(0,0);
414 Contains_static_instance
csi(10,20);
416 class Contains_nested_static_instance
422 Nested(int i
) : z(i
) {}
424 static Contains_nested_static_instance xx
;
427 Contains_nested_static_instance(int i
, int j
) : x(i
), y(j
) {}
432 static Contains_nested_static_instance null
;
436 Contains_nested_static_instance
Contains_nested_static_instance::null(0, 0);
437 Contains_nested_static_instance::Nested
Contains_nested_static_instance::yy(5);
438 Contains_nested_static_instance
439 Contains_nested_static_instance::Nested::xx(1,2);
440 Contains_nested_static_instance
cnsi(30,40);
446 tagless_struct v_tagless
;
448 /* Try to get the compiler to allocate a class in a register. */
461 void marker_reg1 () {}
466 /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
467 might put this variable in a register. This is a lose, though, because
468 it means that GDB can't call any methods for that variable. */
473 /* Perform a computation sufficiently complicated that optimizing compilers
474 won't optimized out the variable. If some compiler constant-folds this
475 whole loop, maybe using a parameter to this function here would help. */
477 for (i
= 0; i
< 13; ++i
)
479 --v
.x
; /* v.x is now 77 */
487 v_bool_array
[0] = false;
488 v_bool_array
[1] = v_bool
;
504 /* FIXME: pmi gets optimized out. Need to do some more computation with
505 it or something. (No one notices, because the test is xfail'd anyway,
506 but that probably won't always be true...). */
507 int Foo::* pmi
= &Foo::y
;
509 /* Make sure the AIX linker doesn't remove the variable. */
512 /* Class with enumeration inside it */
513 ClassWithEnum obj_with_enum
;
514 obj_with_enum
.priv_enum
= ClassWithEnum::red
;
516 obj_with_enum
.priv_enum
= ClassWithEnum::green
;
521 /* Create an instance for some classes, otherwise they get optimized away. */
523 default_public_struct default_public_s
;
524 explicit_public_struct explicit_public_s
;
525 protected_struct protected_s
;
526 private_struct private_s
;
527 mixed_protection_struct mixed_protection_s
;
528 public_class public_c
;
529 protected_class protected_c
;
530 default_private_class default_private_c
;
531 explicit_private_class explicit_private_c
;
532 mixed_protection_class mixed_protection_c
;