[clang] [clang][Sema] Improve `collectViableConversionCandidates` (PR #97908)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 6 12:58:12 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (MagentaTreehouse)
<details>
<summary>Changes</summary>
* 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
---
Full diff: https://github.com/llvm/llvm-project/pull/97908.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaOverload.cpp (+10-16)
``````````diff
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);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/97908
More information about the cfe-commits
mailing list