Skip to content

Commit

Permalink
[clang][Sema] Improve collectViableConversionCandidates (llvm#97908)
Browse files Browse the repository at this point in the history
* Use range-based for
* The value of `Conv` is not used when `ConvTemplate` is not null, so we
do not need to compute it on that path
  • Loading branch information
MagentaTreehouse authored Sep 14, 2024
1 parent 82034ac commit 1d2f727
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6567,29 +6567,22 @@ static void
collectViableConversionCandidates(Sema &SemaRef, Expr *From, QualType ToType,
UnresolvedSetImpl &ViableConversions,
OverloadCandidateSet &CandidateSet) {
for (unsigned I = 0, N = ViableConversions.size(); I != N; ++I) {
DeclAccessPair FoundDecl = ViableConversions[I];
for (const DeclAccessPair &FoundDecl : ViableConversions.pairs()) {
NamedDecl *D = FoundDecl.getDecl();
CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext());
if (isa<UsingShadowDecl>(D))
D = cast<UsingShadowDecl>(D)->getTargetDecl();

CXXConversionDecl *Conv;
FunctionTemplateDecl *ConvTemplate;
if ((ConvTemplate = dyn_cast<FunctionTemplateDecl>(D)))
Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
else
Conv = cast<CXXConversionDecl>(D);

if (ConvTemplate)
if (auto *ConvTemplate = dyn_cast<FunctionTemplateDecl>(D)) {
SemaRef.AddTemplateConversionCandidate(
ConvTemplate, FoundDecl, ActingContext, From, ToType, CandidateSet,
/*AllowObjCConversionOnExplicit=*/false, /*AllowExplicit*/ true);
else
SemaRef.AddConversionCandidate(Conv, FoundDecl, ActingContext, From,
ToType, CandidateSet,
/*AllowObjCConversionOnExplicit=*/false,
/*AllowExplicit*/ true);
/*AllowObjCConversionOnExplicit=*/false, /*AllowExplicit=*/true);
continue;
}
CXXConversionDecl *Conv = cast<CXXConversionDecl>(D);
SemaRef.AddConversionCandidate(
Conv, FoundDecl, ActingContext, From, ToType, CandidateSet,
/*AllowObjCConversionOnExplicit=*/false, /*AllowExplicit=*/true);
}
}

Expand Down

0 comments on commit 1d2f727

Please sign in to comment.