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