]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/chained-calls.cc
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / chained-calls.cc
CommitLineData
6c659fc2
SC
1/* This testcase is part of GDB, the GNU debugger.
2
213516ef 3 Copyright 2014-2023 Free Software Foundation, Inc.
6c659fc2
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
18class S
19{
20public:
21 S () { }
22 S (S &obj);
23
24 S operator+ (const S &s);
25
26 int a;
27};
28
29S::S (S &obj)
30{
31 a = obj.a;
32}
33
34S
35S::operator+ (const S &s)
36{
37 S res;
38
39 res.a = a + s.a;
40
41 return res;
42}
43
44S
45f (int i)
46{
47 S s;
48
49 s.a = i;
50
51 return s;
52}
53
54int
55g (const S &s)
56{
57 return s.a;
58}
59
60class A
61{
62public:
63 A operator+ (const A &);
64 int a;
65};
66
67A
68A::operator+ (const A &obj)
69{
70 A n;
71
72 n.a = a + obj.a;
73
74 return n;
75}
76
77A
78p ()
79{
80 A a;
81 a.a = 12345678;
82 return a;
83}
84
85A
86r ()
87{
88 A a;
89 a.a = 10000000;
90 return a;
91}
92
93A
94q (const A &a)
95{
96 return a;
97}
98
99class B
100{
101public:
102 int b[1024];
103};
104
105B
106makeb ()
107{
108 B b;
109 int i;
110
111 for (i = 0; i < 1024; i++)
112 b.b[i] = i;
113
114 return b;
115}
116
117int
118getb (const B &b, int i)
119{
120 return b.b[i];
121}
122
123class C
124{
125public:
126 C ();
127 ~C ();
128
129 A operator* ();
130
131 A *a_ptr;
132};
133
134C::C ()
135{
136 a_ptr = new A;
137 a_ptr->a = 5678;
138}
139
140C::~C ()
141{
142 delete a_ptr;
143}
144
145A
146C::operator* ()
147{
148 return *a_ptr;
149}
150
151#define TYPE_INDEX 1
152
153enum type
154{
155 INT,
156 CHAR
157};
158
159union U
160{
161public:
162 U (type t);
163 type get_type ();
164
165 int a;
166 char c;
167 type tp[2];
168};
169
170U::U (type t)
171{
172 tp[TYPE_INDEX] = t;
173}
174
175U
176make_int ()
177{
178 return U (INT);
179}
180
181U
182make_char ()
183{
184 return U (CHAR);
185}
186
187type
188U::get_type ()
189{
190 return tp[TYPE_INDEX];
191}
192
193int
194main ()
195{
196 int i = g(f(0));
197 A a = q(p() + r());
198
199 B b = makeb ();
200 C c;
201
202 return i + getb(b, 0); /* Break here */
203}