1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 // Test various -*- C++ -*- things.
23 // ====================== basic C++ types =======================
27 typedef struct fleep fleep
;
28 struct fleep
{ int a
; } s
;
30 // ====================== simple class structures =======================
32 struct default_public_struct
{
33 // defaults to public:
38 struct explicit_public_struct
{
44 struct protected_struct
{
50 struct private_struct
{
56 struct mixed_protection_struct
{
80 class protected_class
{
86 class default_private_class
{
87 // defaults to private:
92 class explicit_private_class
{
98 class mixed_protection_class
{
116 class const_vol_method_class
{
120 int foo (int &) const;
121 int bar (int &) volatile;
122 int baz (int &) const volatile;
125 int const_vol_method_class::foo (int & ir
) const
129 int const_vol_method_class::bar (int & ir
) volatile
133 int const_vol_method_class::baz (int & ir
) const volatile
138 // ========================= simple inheritance ==========================
164 class D
: public B
, public C
{
180 class class_with_anon_union
191 class_with_anon_union g_anon_union
;
193 void inheritance2 (void)
197 void inheritance1 (void)
207 // {{A::a,A::x},B::b,B::x}
214 // {{A::a,A::x},C::c,C::x}
221 // {{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}
223 // The following initialization code is non-portable, but allows us
224 // to initialize all members of g_D until we can fill in the missing
225 // initialization code with legal C++ code.
227 for (intp
= (int *) &g_D
, ival
= 11;
228 intp
< ((int *) &g_D
+ sizeof (g_D
) / sizeof (int));
234 // Overlay the nonportable initialization with legal initialization.
236 // ????? = 11; (g_D.A::a = 11; is ambiguous)
237 // ????? = 12; (g_D.A::x = 12; is ambiguous)
240 This should take care of it. Rather than try to initialize using an ambiguous
241 construct, use 2 unambiguous ones for each. Since the ambiguous a/x member is
242 coming from C, and B, initialize D's C::a, and B::a, and D's C::x and B::x.
258 // {{{{A::a,A::x},B::b,B::x},{{A::a,A::x},C::c,C::x},D::d,D::x}},E::e,E::x}
260 // The following initialization code is non-portable, but allows us
261 // to initialize all members of g_D until we can fill in the missing
262 // initialization code with legal C++ code.
264 for (intp
= (int *) &g_E
, ival
= 21;
265 intp
< ((int *) &g_E
+ sizeof (g_E
) / sizeof (int));
271 // Overlay the nonportable initialization with legal initialization.
273 // ????? = 21; (g_E.A::a = 21; is ambiguous)
274 // ????? = 22; (g_E.A::x = 22; is ambiguous)
286 g_anon_union
.one
= 1;
292 // ======================== static member functions =====================
296 static void ii(int, int);
298 void Static::ii (int, int) { }
300 // ======================== virtual base classes=========================
310 class vB
: public virtual vA
{
318 class vC
: public virtual vA
{
326 class vD
: public virtual vB
, public virtual vC
{
334 class vE
: public virtual vD
{
342 void inheritance4 (void)
346 void inheritance3 (void)
356 // {{vA::va, vA::vx}, vB::vb, vB::vx}
363 // {{vA::va, vA::vx}, vC::vc, vC::vx}
370 // {{{{vA::va, vA::vx}, vB::vb, vB::vx}, vC::vc, vC::vx}, vD::vd,vD::vx}
382 // {{{{{vA::va,vA::vx},vB::vb,vB::vx},vC::vc,vC::vx},vD::vd,vD::vx},vE::ve,vE::vx}
398 // ======================================================================
403 Base1(int i
) { x
= i
; }
412 Foo (int i
, int j
) { x
= i
; y
= j
; }
418 class Bar
: public Base1
, public Foo
{
421 Bar (int i
, int j
, int k
) : Base1 (10*k
), Foo (i
, j
) { z
= k
; }
424 int Foo::operator! () { return !x
; }
426 int Foo::times (int y
) { return x
* y
; }
430 Foo::operator int() { return x
; }
435 class ClassWithEnum
{
437 enum PrivEnum
{ red
, green
, blue
, yellow
= 42 };
446 /* classes.exp relies on statement order in this function for testing
447 enumeration fields. */
451 ClassWithEnum obj_with_enum
;
452 obj_with_enum
.priv_enum
= ClassWithEnum::red
;
455 obj_with_enum
.priv_enum
= ClassWithEnum::green
;
460 int Aptr_a (A
*a
) { return a
->a
; }
461 int Aptr_x (A
*a
) { return a
->x
; }
462 int Aref_a (A
&a
) { return a
.a
; }
463 int Aref_x (A
&a
) { return a
.x
; }
464 int Aval_a (A a
) { return a
.a
; }
465 int Aval_x (A a
) { return a
.x
; }
468 ClassParam class_param
;
470 class Contains_static_instance
475 Contains_static_instance (int i
, int j
) { x
= i
; y
= j
; }
476 static Contains_static_instance null
;
479 Contains_static_instance
Contains_static_instance::null(0,0);
480 Contains_static_instance
csi(10,20);
482 class Contains_nested_static_instance
488 Nested(int i
) : z(i
) {}
490 static Contains_nested_static_instance xx
;
493 Contains_nested_static_instance(int i
, int j
) : x(i
), y(j
) {}
498 static Contains_nested_static_instance null
;
502 Contains_nested_static_instance
Contains_nested_static_instance::null(0, 0);
503 Contains_nested_static_instance::Nested
Contains_nested_static_instance::yy(5);
504 Contains_nested_static_instance
505 Contains_nested_static_instance::Nested::xx(1,2);
506 Contains_nested_static_instance
cnsi(30,40);
512 tagless_struct v_tagless
;
514 /* Try to get the compiler to allocate a class in a register. */
527 void marker_reg1 () {}
532 /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
533 might put this variable in a register. This is a lose, though, because
534 it means that GDB can't call any methods for that variable. */
539 /* Perform a computation sufficiently complicated that optimizing compilers
540 won't optimized out the variable. If some compiler constant-folds this
541 whole loop, maybe using a parameter to this function here would help. */
543 for (i
= 0; i
< 13; ++i
)
545 --v
.x
; /* v.x is now 77 */
553 v_bool_array
[0] = false;
554 v_bool_array
[1] = v_bool
;
559 /* Refer to methods so that they don't get optimized away. */
561 i
= class_param
.Aptr_a (&g_A
);
562 i
= class_param
.Aptr_x (&g_A
);
563 i
= class_param
.Aref_a (g_A
);
564 i
= class_param
.Aref_x (g_A
);
565 i
= class_param
.Aval_a (g_A
);
566 i
= class_param
.Aval_x (g_A
);
583 /* FIXME: pmi gets optimized out. Need to do some more computation with
584 it or something. (No one notices, because the test is xfail'd anyway,
585 but that probably won't always be true...). */
586 int Foo::* pmi
= &Foo::y
;
588 /* Make sure the AIX linker doesn't remove the variable. */
596 /* Create an instance for some classes, otherwise they get optimized away. */
598 default_public_struct default_public_s
;
599 explicit_public_struct explicit_public_s
;
600 protected_struct protected_s
;
601 private_struct private_s
;
602 mixed_protection_struct mixed_protection_s
;
603 public_class public_c
;
604 protected_class protected_c
;
605 default_private_class default_private_c
;
606 explicit_private_class explicit_private_c
;
607 mixed_protection_class mixed_protection_c
;