Skip to content

Commit a2e6a7d

Browse files
skip using specilised function for methods
Using `AddOverloadCandidate` over `AddMethodCandidate` and `AddTemplateOverloadCandidate` over `AddMethodTemplateCandidate`
1 parent a434593 commit a2e6a7d

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,13 +1066,19 @@ namespace Cpp {
10661066
cling::Interpreter::PushTransactionRAII RAII(&getInterp());
10671067
#endif
10681068

1069+
// The overload resolution interfaces in Sema require a list of expressions.
1070+
// However, unlike handwritten C++, we do not always have a expression.
1071+
// Here we synthesize a placeholder expression to be able to use
1072+
// Sema::AddOverloadCandidate. Made up expressions are fine because the
1073+
// interface uses the list size and the expression types.
10691074
llvm::SmallVector<Expr*> Args;
1075+
Args.reserve(arg_types.size());
10701076
for (auto i : arg_types) {
10711077
QualType Type = QualType::getFromOpaquePtr(i.m_Type);
10721078
ExprValueKind ExprKind = ExprValueKind::VK_PRValue;
10731079
if (Type->isReferenceType())
10741080
ExprKind = ExprValueKind::VK_LValue;
1075-
Args.push_back(new (getSema().getASTContext())
1081+
Args.push_back(new (C)
10761082
OpaqueValueExpr(SourceLocation::getFromRawEncoding(1),
10771083
Type.getNonReferenceType(), ExprKind));
10781084
}
@@ -1093,37 +1099,26 @@ namespace Cpp {
10931099
}
10941100
}
10951101

1096-
TemplateArgumentListInfo TLI{};
1102+
TemplateArgumentListInfo ExplicitTemplateArgs{};
10971103
for (auto TA : TemplateArgs)
1098-
TLI.addArgument(
1104+
ExplicitTemplateArgs.addArgument(
10991105
S.getTrivialTemplateArgumentLoc(TA, QualType(), SourceLocation()));
11001106

11011107
OverloadCandidateSet Overloads(
11021108
SourceLocation(), OverloadCandidateSet::CandidateSetKind::CSK_Normal);
1109+
11031110
for (void* i : candidates) {
11041111
Decl* D = static_cast<Decl*>(i);
1105-
if (auto* MD = dyn_cast<CXXMethodDecl>(D)) {
1106-
S.AddMethodCandidate(
1107-
MD, DeclAccessPair::make(MD, MD->getAccess()), MD->getParent(),
1108-
C.getTypeDeclType(MD->getParent()),
1109-
Expr::Classification::makeSimpleLValue(), Args, Overloads);
1110-
} else if (auto* FD = dyn_cast<FunctionDecl>(D)) {
1112+
if (auto* FD = dyn_cast<FunctionDecl>(D)) {
11111113
S.AddOverloadCandidate(FD, DeclAccessPair::make(FD, FD->getAccess()),
11121114
Args, Overloads);
11131115
} else if (auto* FTD = dyn_cast<FunctionTemplateDecl>(D)) {
1114-
if (auto* CXXRD =
1115-
dyn_cast<CXXRecordDecl>(FTD->getTemplatedDecl()->getParent())) {
1116-
S.AddMethodTemplateCandidate(
1117-
FTD, DeclAccessPair::make(FTD, FTD->getAccess()), CXXRD, &TLI,
1118-
C.getTypeDeclType(CXXRD),
1119-
Expr::Classification::makeSimpleLValue(), Args, Overloads);
1120-
} else {
1121-
S.AddTemplateOverloadCandidate(
1122-
FTD, DeclAccessPair::make(FTD, FTD->getAccess()), &TLI, Args,
1123-
Overloads);
1124-
}
1116+
S.AddTemplateOverloadCandidate(
1117+
FTD, DeclAccessPair::make(FTD, FTD->getAccess()),
1118+
&ExplicitTemplateArgs, Args, Overloads);
11251119
}
11261120
}
1121+
11271122
OverloadCandidateSet::iterator Best;
11281123
Overloads.BestViableFunction(S, SourceLocation(), Best);
11291124

0 commit comments

Comments
 (0)