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)
220 This should take care of it. Rather than try to initialize using an ambiguous
221 construct, use 2 unambiguous ones for each. Since the ambiguous a/x member is
222 coming from C, and B, initialize D's C::a, and B::a, and D's C::x and B::x.
238 // {{{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}},E::e,E::x}
240 // The following initialization code is non-portable, but allows us
241 // to initialize all members of g_D until we can fill in the missing
242 // initialization code with legal C++ code.
244 for (intp
= (int *) &g_E
, ival
= 21;
245 intp
< ((int *) &g_E
+ sizeof (g_E
) / sizeof (int));
251 // Overlay the nonportable initialization with legal initialization.
253 // ????? = 21; (g_E.A::a = 21; is ambiguous)
254 // ????? = 22; (g_E.A::x = 22; is ambiguous)
266 g_anon_union
.one
= 1;
272 // ======================== virtual base classes=========================
282 class vB
: public virtual vA
{
290 class vC
: public virtual vA
{
298 class vD
: public virtual vB
, public virtual vC
{
306 class vE
: public virtual vD
{
314 void inheritance4 (void)
318 void inheritance3 (void)
328 // {{vA::va, vA::vx}, vB::vb, vB::vx}
335 // {{vA::va, vA::vx}, vC::vc, vC::vx}
342 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
354 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
370 // ======================================================================
375 Base1(int i
) { x
= i
; }
384 Foo (int i
, int j
) { x
= i
; y
= j
; }
390 class Bar
: public Base1
, public Foo
{
393 Bar (int i
, int j
, int k
) : Base1 (10*k
), Foo (i
, j
) { z
= k
; }
396 int Foo::operator! () { return !x
; }
398 int Foo::times (int y
) { return x
* y
; }
402 Foo::operator int() { return x
; }
407 class ClassWithEnum
{
409 enum PrivEnum
{ red
, green
, blue
, yellow
= 42 };
418 /* classes.exp relies on statement order in this function for testing
419 enumeration fields. */
423 ClassWithEnum obj_with_enum
;
424 obj_with_enum
.priv_enum
= ClassWithEnum::red
;
427 obj_with_enum
.priv_enum
= ClassWithEnum::green
;
432 int Aptr_a (A
*a
) { return a
->a
; }
433 int Aptr_x (A
*a
) { return a
->x
; }
434 int Aref_a (A
&a
) { return a
.a
; }
435 int Aref_x (A
&a
) { return a
.x
; }
436 int Aval_a (A a
) { return a
.a
; }
437 int Aval_x (A a
) { return a
.x
; }
440 ClassParam class_param
;
442 class Contains_static_instance
447 Contains_static_instance (int i
, int j
) { x
= i
; y
= j
; }
448 static Contains_static_instance null
;
451 Contains_static_instance
Contains_static_instance::null(0,0);
452 Contains_static_instance
csi(10,20);
454 class Contains_nested_static_instance
460 Nested(int i
) : z(i
) {}
462 static Contains_nested_static_instance xx
;
465 Contains_nested_static_instance(int i
, int j
) : x(i
), y(j
) {}
470 static Contains_nested_static_instance null
;
474 Contains_nested_static_instance
Contains_nested_static_instance::null(0, 0);
475 Contains_nested_static_instance::Nested
Contains_nested_static_instance::yy(5);
476 Contains_nested_static_instance
477 Contains_nested_static_instance::Nested::xx(1,2);
478 Contains_nested_static_instance
cnsi(30,40);
484 tagless_struct v_tagless
;
486 /* Try to get the compiler to allocate a class in a register. */
499 void marker_reg1 () {}
504 /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
505 might put this variable in a register. This is a lose, though, because
506 it means that GDB can't call any methods for that variable. */
511 /* Perform a computation sufficiently complicated that optimizing compilers
512 won't optimized out the variable. If some compiler constant-folds this
513 whole loop, maybe using a parameter to this function here would help. */
515 for (i
= 0; i
< 13; ++i
)
517 --v
.x
; /* v.x is now 77 */
525 v_bool_array
[0] = false;
526 v_bool_array
[1] = v_bool
;
531 /* Refer to methods so that they don't get optimized away. */
533 i
= class_param
.Aptr_a (&g_A
);
534 i
= class_param
.Aptr_x (&g_A
);
535 i
= class_param
.Aref_a (g_A
);
536 i
= class_param
.Aref_x (g_A
);
537 i
= class_param
.Aval_a (g_A
);
538 i
= class_param
.Aval_x (g_A
);
555 /* FIXME: pmi gets optimized out. Need to do some more computation with
556 it or something. (No one notices, because the test is xfail'd anyway,
557 but that probably won't always be true...). */
558 int Foo::* pmi
= &Foo::y
;
560 /* Make sure the AIX linker doesn't remove the variable. */
568 /* Create an instance for some classes, otherwise they get optimized away. */
570 default_public_struct default_public_s
;
571 explicit_public_struct explicit_public_s
;
572 protected_struct protected_s
;
573 private_struct private_s
;
574 mixed_protection_struct mixed_protection_s
;
575 public_class public_c
;
576 protected_class protected_c
;
577 default_private_class default_private_c
;
578 explicit_private_class explicit_private_c
;
579 mixed_protection_class mixed_protection_c
;