]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.linespec/cpls.cc
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / cpls.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2017-2024 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 /* Code for the all-param-prefixes test. */
19
20 void
21 param_prefixes_test_long (long)
22 {}
23
24 void
25 param_prefixes_test_intp_intr (int *, int&)
26 {}
27
28 /* Code for the overload test. */
29
30 void
31 overload_ambiguous_test (long)
32 {}
33
34 void
35 overload_ambiguous_test (int, int)
36 {}
37
38 void
39 overload_ambiguous_test (int, long)
40 {}
41
42 /* Code for the overload-2 test. */
43
44 /* Generate functions/methods all with the same name, in different
45 scopes, but all with different parameters. */
46
47 struct overload2_arg1 {};
48 struct overload2_arg2 {};
49 struct overload2_arg3 {};
50 struct overload2_arg4 {};
51 struct overload2_arg5 {};
52 struct overload2_arg6 {};
53 struct overload2_arg7 {};
54 struct overload2_arg8 {};
55 struct overload2_arg9 {};
56 struct overload2_arga {};
57
58 #define GEN_OVERLOAD2_FUNCTIONS(ARG1, ARG2) \
59 void __attribute__ ((used)) \
60 overload2_function (ARG1) \
61 {} \
62 \
63 struct struct_overload2_test \
64 { \
65 void __attribute__ ((used)) \
66 overload2_function (ARG2); \
67 }; \
68 \
69 void __attribute__ ((used)) \
70 struct_overload2_test::overload2_function (ARG2) \
71 {}
72
73 /* In the global namespace. */
74 GEN_OVERLOAD2_FUNCTIONS( overload2_arg1, overload2_arg2)
75
76 namespace
77 {
78 /* In an anonymous namespace. */
79 GEN_OVERLOAD2_FUNCTIONS (overload2_arg3, overload2_arg4)
80 }
81
82 namespace ns_overload2_test
83 {
84 /* In a namespace. */
85 GEN_OVERLOAD2_FUNCTIONS (overload2_arg5, overload2_arg6)
86
87 namespace
88 {
89 /* In a nested anonymous namespace. */
90 GEN_OVERLOAD2_FUNCTIONS (overload2_arg7, overload2_arg8)
91
92 namespace ns_overload2_test
93 {
94 /* In a nested namespace. */
95 GEN_OVERLOAD2_FUNCTIONS (overload2_arg9, overload2_arga)
96 }
97 }
98 }
99
100 /* Code for the overload-3 test. */
101
102 #define GEN_OVERLOAD3_FUNCTIONS(ARG1, ARG2) \
103 void __attribute__ ((used)) \
104 overload3_function (ARG1) \
105 {} \
106 void __attribute__ ((used)) \
107 overload3_function (ARG2) \
108 {} \
109 \
110 struct struct_overload3_test \
111 { \
112 void __attribute__ ((used)) \
113 overload3_function (ARG1); \
114 void __attribute__ ((used)) \
115 overload3_function (ARG2); \
116 }; \
117 \
118 void __attribute__ ((used)) \
119 struct_overload3_test::overload3_function (ARG1) \
120 {} \
121 void __attribute__ ((used)) \
122 struct_overload3_test::overload3_function (ARG2) \
123 {}
124
125 /* In the global namespace. */
126 GEN_OVERLOAD3_FUNCTIONS (int, long)
127
128 namespace
129 {
130 /* In an anonymous namespace. */
131 GEN_OVERLOAD3_FUNCTIONS (int, long)
132 }
133
134 namespace ns_overload3_test
135 {
136 /* In a namespace. */
137 GEN_OVERLOAD3_FUNCTIONS (int, long)
138
139 namespace
140 {
141 /* In a nested anonymous namespace. */
142 GEN_OVERLOAD3_FUNCTIONS (int, long)
143
144 namespace ns_overload3_test
145 {
146 /* In a nested namespace. */
147 GEN_OVERLOAD3_FUNCTIONS (int, long)
148 }
149 }
150 }
151
152 /* Code for the template-function_foo (template parameter completion) tests. */
153
154 template <typename T>
155 struct template_struct
156 {
157 T template_overload_fn (T);
158 };
159
160 template <typename T>
161 T template_struct<T>::template_overload_fn (T t)
162 {
163 return t;
164 }
165
166 template_struct<int> template_struct_int;
167 template_struct<long> template_struct_long;
168
169 /* Code for the template-parameter-overload test. */
170
171 template <typename T>
172 void foo (T c) {}
173
174 template <typename T1, typename T2>
175 void foo (T1 a, T2 b) {}
176
177 template <typename T>
178 struct a
179 {
180 void method () {}
181 };
182
183 template <typename T>
184 struct b
185 {
186 void method () {}
187 };
188
189 template <typename T>
190 struct c
191 {
192 void method () {}
193 };
194
195 template <typename T>
196 struct d
197 {
198 void method () {};
199 };
200
201 template <typename T1, typename T2>
202 struct A
203 {
204 void method () {}
205 };
206
207 template <typename T1, typename T2>
208 struct B
209 {
210 void method () {}
211 };
212
213 namespace n
214 {
215 struct na {};
216 struct nb {};
217
218 template <typename T1, typename T2>
219 struct NA {};
220
221 template <typename T1, typename T2>
222 struct NB {};
223 };
224
225 static void
226 template_function_foo ()
227 {
228 a<a<int>> aa;
229 aa.method ();
230 a<b<int>> ab;
231 ab.method ();
232 c<c<int>> cc;
233 cc.method ();
234 c<d<int>> cd;
235 cd.method ();
236 foo (aa);
237 foo (ab);
238 foo (cc);
239 foo (cd);
240 foo (aa, ab);
241 foo (aa, cc);
242 foo (aa, cd);
243
244 A<a<b<int>>, c<d<int>>> Aabcd;
245 Aabcd.method ();
246 foo (Aabcd);
247
248 A<a<b<int>>, a<a<int>>> Aabaa;
249 Aabaa.method ();
250 foo (Aabaa);
251
252 A<a<b<int>>, a<b<int>>> Aabab;
253 Aabab.method ();
254 foo (Aabab);
255
256 B<a<b<int>>, c<d<int>>> Babcd;
257 Babcd.method ();
258 foo (Babcd);
259
260 foo (Aabcd, Babcd);
261 foo (Aabcd, Aabaa);
262 foo (Aabcd, Aabab);
263
264 n::na na;
265 n::nb nb;
266 foo (na, nb);
267 a<n::na> ana;
268 b<n::nb> bnb;
269 foo (ana, bnb);
270
271 n::NA<n::na, n::nb> NAnanb;
272 n::NB<n::na, n::nb> Nbnanb;
273 foo (NAnanb, Nbnanb);
274 }
275
276 /* Code for the template2-ret-type tests. */
277
278 template <typename T>
279 struct template2_ret_type {};
280
281 template <typename T>
282 struct template2_struct
283 {
284 template <typename T2, typename T3>
285 T template2_fn (T = T (), T2 t2 = T2 (), T3 t3 = T3 ());
286 };
287
288 template <typename T>
289 template <typename T2, typename T3>
290 T template2_struct<T>::template2_fn (T t, T2 t2, T3 t3)
291 {
292 return T ();
293 }
294
295 template2_struct<template2_ret_type<int> > template2_struct_inst;
296
297 /* Code for the const-overload tests. */
298
299 struct struct_with_const_overload
300 {
301 void const_overload_fn ();
302 void const_overload_fn () const;
303 };
304
305 void
306 struct_with_const_overload::const_overload_fn ()
307 {}
308
309 void
310 struct_with_const_overload::const_overload_fn () const
311 {}
312
313 void
314 not_overloaded_fn ()
315 {}
316
317 /* Code for the incomplete-scope-colon tests. */
318
319 struct struct_incomplete_scope_colon_test
320 {
321 void incomplete_scope_colon_test ();
322 };
323
324 void
325 struct_incomplete_scope_colon_test::incomplete_scope_colon_test ()
326 {}
327
328 namespace ns_incomplete_scope_colon_test
329 {
330 void incomplete_scope_colon_test () {}
331 }
332
333 namespace ns2_incomplete_scope_colon_test
334 {
335 struct struct_in_ns2_incomplete_scope_colon_test
336 {
337 void incomplete_scope_colon_test ();
338 };
339
340 void
341 struct_in_ns2_incomplete_scope_colon_test::incomplete_scope_colon_test ()
342 {}
343 }
344
345 /* Code for the anon-ns tests. */
346
347 namespace
348 {
349 void __attribute__ ((used)) anon_ns_function ()
350 {}
351
352 struct anon_ns_struct
353 {
354 void __attribute__ ((used)) anon_ns_function ();
355 };
356
357 void __attribute__ ((used))
358 anon_ns_struct::anon_ns_function ()
359 {}
360 }
361
362 namespace the_anon_ns_wrapper_ns
363 {
364
365 namespace
366 {
367 void __attribute__ ((used)) anon_ns_function ()
368 {}
369
370 struct anon_ns_struct
371 {
372 void __attribute__ ((used)) anon_ns_function ();
373 };
374
375 void __attribute__ ((used))
376 anon_ns_struct::anon_ns_function ()
377 {}
378 }
379
380 } /* the_anon_ns_wrapper_ns */
381
382 /* Code for the global-ns-scope-op tests. */
383
384 void global_ns_scope_op_function ()
385 {
386 }
387
388 /* Add a function with the same name to a namespace. We want to test
389 that "b ::global_ns_function" does NOT select it. */
390 namespace the_global_ns_scope_op_ns
391 {
392 void global_ns_scope_op_function ()
393 {
394 }
395 }
396
397 /* Code for the ambiguous-prefix tests. */
398
399 /* Create a few functions/methods with the same "ambiguous_prefix_"
400 prefix. They in different scopes, but "b ambiguous_prefix_<tab>"
401 should list them all, and figure out the LCD is
402 ambiguous_prefix_. */
403
404 void ambiguous_prefix_global_func ()
405 {
406 }
407
408 namespace the_ambiguous_prefix_ns
409 {
410 void ambiguous_prefix_ns_func ()
411 {
412 }
413 }
414
415 struct the_ambiguous_prefix_struct
416 {
417 void ambiguous_prefix_method ();
418 };
419
420 void
421 the_ambiguous_prefix_struct::ambiguous_prefix_method ()
422 {
423 }
424
425 /* Code for the function-labels test. */
426
427 int
428 function_with_labels (int i)
429 {
430 if (i > 0)
431 {
432 label1:
433 return i + 20;
434 }
435 else
436 {
437 label2:
438 return i + 10;
439 }
440 }
441
442 /* Code for the no-data-symbols and if-expression tests. */
443
444 int code_data = 0;
445
446 int another_data = 0;
447
448 /* A function that has a same "code" prefix as the global above. We
449 want to ensure that completing on "b code" doesn't offer the data
450 symbol. */
451 void
452 code_function ()
453 {
454 }
455
456 /* Code for the operator< tests. */
457
458 enum foo_enum
459 {
460 foo_value
461 };
462
463 bool operator<(foo_enum lhs, foo_enum rhs)
464 {
465 label1:
466 return false;
467 }
468
469 /* Code for the in-source-file-unconstrained /
470 in-source-file-ambiguous tests. */
471
472 int
473 file_constrained_test_cpls_function (int i)
474 {
475 if (i > 0)
476 {
477 label1:
478 return i + 20;
479 }
480 else
481 {
482 label2:
483 return i + 10;
484 }
485 }
486
487
488 int
489 main ()
490 {
491 template2_struct_inst.template2_fn<int, int> ();
492 template_struct_int.template_overload_fn(0);
493 template_struct_long.template_overload_fn(0);
494 template_function_foo ();
495
496 return 0;
497 }