Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-xmethods.cc
CommitLineData
883964a7
SC
1/* This testcase is part of GDB, the GNU debugger.
2
88b9d363 3 Copyright 2014-2022 Free Software Foundation, Inc.
883964a7
SC
4
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.
9
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.
14
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/>. */
17
883964a7
SC
18namespace dop
19{
20
21class A
22{
23public:
24 int a;
25 int array [10];
26 virtual ~A ();
27 int operator+ (const A &obj);
28 int operator- (const A &obj);
29 virtual int geta (void);
30};
31
32A::~A () { }
33
5d376983
SC
34int a_plus_a = 0;
35
883964a7
SC
36int
37A::operator+ (const A &obj)
38{
5d376983 39 a_plus_a++;
883964a7
SC
40 return a + obj.a;
41}
42
5d376983
SC
43int a_minus_a = 0;
44
883964a7
SC
45int
46A::operator- (const A &obj)
47{
5d376983 48 a_minus_a++;
883964a7
SC
49 return a - obj.a;
50}
51
5d376983
SC
52int a_geta = 0;
53
883964a7
SC
54int
55A::geta (void)
56{
5d376983 57 a_geta++;
883964a7
SC
58 return a;
59}
60
61class B : public A
62{
63public:
64 virtual int geta (void);
65};
66
5d376983
SC
67int b_geta = 0;
68
883964a7
SC
69int
70B::geta (void)
71{
5d376983 72 b_geta++;
883964a7
SC
73 return 2 * a;
74}
75
76typedef B Bt;
77
78typedef Bt Btt;
79
80class E : public A
81{
82public:
83 /* This class has a member named 'a', while the base class also has a
84 member named 'a'. When one invokes A::geta(), A::a should be
85 returned and not E::a as the 'geta' method is defined on class 'A'.
86 This class tests this aspect of debug methods. */
87 int a;
88};
89
90template <typename T>
91class G
92{
93 public:
94 template <typename T1>
95 int size_diff ();
96
97 template <int M>
98 int size_mul ();
99
100 template <typename T1>
101 T mul(const T1 t1);
102
103 public:
104 T t;
105};
106
5d376983
SC
107int g_size_diff = 0;
108
883964a7
SC
109template <typename T>
110template <typename T1>
111int
112G<T>::size_diff ()
113{
5d376983 114 g_size_diff++;
883964a7
SC
115 return sizeof (T1) - sizeof (T);
116}
117
5d376983
SC
118int g_size_mul = 0;
119
883964a7
SC
120template <typename T>
121template <int M>
122int
123G<T>::size_mul ()
124{
5d376983 125 g_size_mul++;
883964a7
SC
126 return M * sizeof (T);
127}
128
5d376983
SC
129int g_mul = 0;
130
883964a7
SC
131template <typename T>
132template <typename T1>
133T
134G<T>::mul (const T1 t1)
135{
5d376983 136 g_mul++;
883964a7
SC
137 return t1 * t;
138}
139
140} // namespaxe dop
141
142using namespace dop;
143
144int main(void)
145{
146 A a1, a2;
147 a1.a = 5;
148 a2.a = 10;
149
150 B b1;
151 b1.a = 30;
152 A *a_ptr = &b1;
153
154 Bt bt;
155 bt.a = 40;
156
157 Btt btt;
158 btt.a = -5;
159
160 G<int> g, *g_ptr;
161 g.t = 5;
162 g_ptr = &g;
163
164 E e;
165 E &e_ref = e;
166 E *e_ptr = &e;
167 e.a = 1000;
168 e.A::a = 100;
169
170 int diff = g.size_diff<float> ();
171 int smul = g.size_mul<2> ();
172 int mul = g.mul (1.0);
173
174 for (int i = 0; i < 10; i++)
175 {
4c082a81 176 a1.array[i] = a2.array[i] = b1.array[i] = i;
883964a7
SC
177 }
178
179 return 0; /* Break here. */
180}
This page took 1.029922 seconds and 4 git commands to generate.