[clang] [clang][Sema] Improve `collectViableConversionCandidates` (PR #97908)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 6 13:43:00 PDT 2024
https://github.com/MagentaTreehouse updated https://github.com/llvm/llvm-project/pull/97908
>From def9d161e4ea79ee1b24a8d662a5c0dd17c2dd8f Mon Sep 17 00:00:00 2001
From: Mingyi Chen <cmingyi01 at gmail.com>
Date: Sat, 6 Jul 2024 15:41:08 -0400
Subject: [PATCH 1/2] [clang][Sema] Improve `collectViableConversionCandidates`
* 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 | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5ea6b06121c7c..95c433dab4da4 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6504,29 +6504,23 @@ 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 (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);
}
}
>From 55267b7cfa948d62620fcf12f6ac4afea9a6f3ed Mon Sep 17 00:00:00 2001
From: Mingyi Chen <cmingyi01 at gmail.com>
Date: Sat, 6 Jul 2024 16:41:57 -0400
Subject: [PATCH 2/2] Format
---
clang/lib/Sema/SemaOverload.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 95c433dab4da4..f63495731315e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6517,10 +6517,9 @@ collectViableConversionCandidates(Sema &SemaRef, Expr *From, QualType ToType,
continue;
}
CXXConversionDecl *Conv = cast<CXXConversionDecl>(D);
- SemaRef.AddConversionCandidate(Conv, FoundDecl, ActingContext, From, ToType,
- CandidateSet,
- /*AllowObjCConversionOnExplicit=*/false,
- /*AllowExplicit=*/true);
+ SemaRef.AddConversionCandidate(
+ Conv, FoundDecl, ActingContext, From, ToType, CandidateSet,
+ /*AllowObjCConversionOnExplicit=*/false, /*AllowExplicit=*/true);
}
}
More information about the cfe-commits
mailing list