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 // ======================== static member functions =====================
276 static void ii(int, int);
278 void Static::ii (int, int) { }
280 // ======================== virtual base classes=========================
290 class vB
: public virtual vA
{
298 class vC
: public virtual vA
{
306 class vD
: public virtual vB
, public virtual vC
{
314 class vE
: public virtual vD
{
322 void inheritance4 (void)
326 void inheritance3 (void)
336 // {{vA::va, vA::vx}, vB::vb, vB::vx}
343 // {{vA::va, vA::vx}, vC::vc, vC::vx}
350 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
362 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
378 // ======================================================================
383 Base1(int i
) { x
= i
; }
392 Foo (int i
, int j
) { x
= i
; y
= j
; }
398 class Bar
: public Base1
, public Foo
{
401 Bar (int i
, int j
, int k
) : Base1 (10*k
), Foo (i
, j
) { z
= k
; }
404 int Foo::operator! () { return !x
; }
406 int Foo::times (int y
) { return x
* y
; }
410 Foo::operator int() { return x
; }
415 class ClassWithEnum
{
417 enum PrivEnum
{ red
, green
, blue
, yellow
= 42 };
426 /* classes.exp relies on statement order in this function for testing
427 enumeration fields. */
431 ClassWithEnum obj_with_enum
;
432 obj_with_enum
.priv_enum
= ClassWithEnum::red
;
435 obj_with_enum
.priv_enum
= ClassWithEnum::green
;
440 int Aptr_a (A
*a
) { return a
->a
; }
441 int Aptr_x (A
*a
) { return a
->x
; }
442 int Aref_a (A
&a
) { return a
.a
; }
443 int Aref_x (A
&a
) { return a
.x
; }
444 int Aval_a (A a
) { return a
.a
; }
445 int Aval_x (A a
) { return a
.x
; }
448 ClassParam class_param
;
450 class Contains_static_instance
455 Contains_static_instance (int i
, int j
) { x
= i
; y
= j
; }
456 static Contains_static_instance null
;
459 Contains_static_instance
Contains_static_instance::null(0,0);
460 Contains_static_instance
csi(10,20);
462 class Contains_nested_static_instance
468 Nested(int i
) : z(i
) {}
470 static Contains_nested_static_instance xx
;
473 Contains_nested_static_instance(int i
, int j
) : x(i
), y(j
) {}
478 static Contains_nested_static_instance null
;
482 Contains_nested_static_instance
Contains_nested_static_instance::null(0, 0);
483 Contains_nested_static_instance::Nested
Contains_nested_static_instance::yy(5);
484 Contains_nested_static_instance
485 Contains_nested_static_instance::Nested::xx(1,2);
486 Contains_nested_static_instance
cnsi(30,40);
492 tagless_struct v_tagless
;
494 /* Try to get the compiler to allocate a class in a register. */
507 void marker_reg1 () {}
512 /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
513 might put this variable in a register. This is a lose, though, because
514 it means that GDB can't call any methods for that variable. */
519 /* Perform a computation sufficiently complicated that optimizing compilers
520 won't optimized out the variable. If some compiler constant-folds this
521 whole loop, maybe using a parameter to this function here would help. */
523 for (i
= 0; i
< 13; ++i
)
525 --v
.x
; /* v.x is now 77 */
533 v_bool_array
[0] = false;
534 v_bool_array
[1] = v_bool
;
539 /* Refer to methods so that they don't get optimized away. */
541 i
= class_param
.Aptr_a (&g_A
);
542 i
= class_param
.Aptr_x (&g_A
);
543 i
= class_param
.Aref_a (g_A
);
544 i
= class_param
.Aref_x (g_A
);
545 i
= class_param
.Aval_a (g_A
);
546 i
= class_param
.Aval_x (g_A
);
563 /* FIXME: pmi gets optimized out. Need to do some more computation with
564 it or something. (No one notices, because the test is xfail'd anyway,
565 but that probably won't always be true...). */
566 int Foo::* pmi
= &Foo::y
;
568 /* Make sure the AIX linker doesn't remove the variable. */
576 /* Create an instance for some classes, otherwise they get optimized away. */
578 default_public_struct default_public_s
;
579 explicit_public_struct explicit_public_s
;
580 protected_struct protected_s
;
581 private_struct private_s
;
582 mixed_protection_struct mixed_protection_s
;
583 public_class public_c
;
584 protected_class protected_c
;
585 default_private_class default_private_c
;
586 explicit_private_class explicit_private_c
;
587 mixed_protection_class mixed_protection_c
;