From 1d2f7277e695d046efaf2818dd1a4b251ce745fd Mon Sep 17 00:00:00 2001 From: MagentaTreehouse <99200384+MagentaTreehouse@users.noreply.github.com> Date: Sat, 14 Sep 2024 03:00:48 -0400 Subject: [PATCH] [clang][Sema] Improve `collectViableConversionCandidates` (#97908) * 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 --- clang/lib/Sema/SemaOverload.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index a155bb2fd3ba2a..0c1e054f7c30a4 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -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(D->getDeclContext()); if (isa(D)) D = cast(D)->getTargetDecl(); - CXXConversionDecl *Conv; - FunctionTemplateDecl *ConvTemplate; - if ((ConvTemplate = dyn_cast(D))) - Conv = cast(ConvTemplate->getTemplatedDecl()); - else - Conv = cast(D); - - if (ConvTemplate) + if (auto *ConvTemplate = dyn_cast(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(D); + SemaRef.AddConversionCandidate( + Conv, FoundDecl, ActingContext, From, ToType, CandidateSet, + /*AllowObjCConversionOnExplicit=*/false, /*AllowExplicit=*/true); } }