[clang] 1d2f727 - [clang][Sema] Improve `collectViableConversionCandidates` (#97908)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 14 00:00:51 PDT 2024
Author: MagentaTreehouse
Date: 2024-09-14T09:00:48+02:00
New Revision: 1d2f7277e695d046efaf2818dd1a4b251ce745fd
URL: https://github.com/llvm/llvm-project/commit/1d2f7277e695d046efaf2818dd1a4b251ce745fd
DIFF: https://github.com/llvm/llvm-project/commit/1d2f7277e695d046efaf2818dd1a4b251ce745fd.diff
LOG: [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
Added:
Modified:
clang/lib/Sema/SemaOverload.cpp
Removed:
################################################################################
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<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);
}
}
More information about the cfe-commits
mailing list