Allow findAnyFunction to discover a template instance without any argument hints

This allows to find an existing function template instance even based on only
the template name (of course, in this case, no instantiation is done, only already
existing ones can be returned).

This allows add there same features to TListOfFunctions::FindObject and
TViewAllPublicFunctions::FindObject.
This commit is contained in:
Philippe Canal 2013-11-11 12:00:39 -06:00 committed by sftnight
parent 77c8f50434
commit e0e2df65e5
2 changed files with 16 additions and 1 deletions

View File

@ -941,6 +941,13 @@ namespace cling {
if (res) return res;
FunctionTemplateDecl *MethodTmpl =dyn_cast<FunctionTemplateDecl>(aResult);
if (MethodTmpl) {
if (!ExplicitTemplateArgs || ExplicitTemplateArgs->size()==0) {
// Not argument was specified, any instantiation will do.
if (MethodTmpl->spec_begin() != MethodTmpl->spec_end()) {
return *( MethodTmpl->spec_begin() );
}
}
// pick a specialization that result match the given arguments
SourceLocation loc;
sema::TemplateDeductionInfo Info(loc);
@ -951,7 +958,7 @@ namespace cling {
fdecl,
Info);
if (Result) {
// deduction failure
// Deduction failure.
return 0;
} else {
// Instantiate the function is needed.

View File

@ -1299,6 +1299,14 @@ func_B_k1_name->print(llvm::errs());
//CHECK-NEXT: float x = v;
//CHECK-NEXT: }
const clang::FunctionDecl* func_B_k1_name_2 = lookup.findAnyFunction(class_A, "B_k");
printf("func_B_k1_name_2: 0x%lx\n", (unsigned long) func_B_k1_name_2);
//CHECK: func_B_k1_name_2: 0x{{[1-9a-f][0-9a-f]*$}}
func_B_k1_name_2->print(llvm::errs());
//CHECK-NEXT: void B_k(int v) {
//CHECK-NEXT: int x = v;
//CHECK-NEXT: }
//
// One final check to make sure we are at the right line in the output.