1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 1998-2024 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 virtual int baz (int z
);
49 int A::foo (int dummy
)
55 int A::bar (int dummy
)
60 return r
+ j
+ 2 * dummy
;
63 int A::baz (int dummy
)
68 return r
+ j
+ 12 * dummy
;
73 return 2 + 13 * dummy
;
76 typedef int (A::*PMF
)(int);
80 /* This class is in front of the other base classes of Diamond, so
81 that we can detect if the offset for Left or the first Base is
82 added twice - otherwise it would be 2 * 0 == 0. */
87 virtual int vspacer();
90 int Padding::vspacer()
100 virtual int vget_base ();
108 int Base::vget_base ()
110 return this->x
+ 1000;
113 class Left
: public Base
{
120 return this->x
+ 100;
123 class Right
: public Base
{
130 return this->x
+ 200;
133 class Diamond
: public Padding
, public Left
, public Right
136 virtual int vget_base ();
137 int (*func_ptr
) (int);
140 int Diamond::vget_base ()
142 return this->Left::x
+ 2000;
166 int (Diamond::*left_pmf
) ();
167 int (Diamond::*right_pmf
) ();
168 int (Diamond::*left_vpmf
) ();
169 int (Diamond::*left_base_vpmf
) ();
170 int (Diamond::*right_vpmf
) ();
171 int (Base::*base_vpmf
) ();
172 int Diamond::*diamond_pmi
;
173 int (* Diamond::*diamond_pfunc_ptr
) (int);
189 diamond
.Left::x
= 77;
190 diamond
.Right::x
= 88;
191 diamond
.func_ptr
= func
;
193 /* Some valid pointer to members from a base class. */
194 left_pmf
= (int (Diamond::*) ()) (int (Left::*) ()) (&Base::get_x
);
195 right_pmf
= (int (Diamond::*) ()) (int (Right::*) ()) (&Base::get_x
);
196 left_vpmf
= &Left::vget
;
197 left_base_vpmf
= (int (Diamond::*) ()) (int (Left::*) ()) (&Base::vget_base
);
198 right_vpmf
= &Right::vget
;
200 /* An unspecified, value preserving pointer to member cast. */
201 base_vpmf
= (int (Base::*) ()) (int (Left::*) ()) &Diamond::vget_base
;
203 /* A pointer to data member from a base class. */
204 diamond_pmi
= (int Diamond::*) (int Left::*) &Base::x
;
206 /* A pointer to data member, where the member is itself a pointer to
208 diamond_pfunc_ptr
= (int (* Diamond::*) (int)) &Diamond::func_ptr
;
214 contain
.member
= &A::j
;
216 pmi
= NULL
; /* Breakpoint 1 here. */
218 (diamond
.*diamond_pfunc_ptr
) (20);