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