Yet another simplifying use of Sema::getMostSpecialized
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82844 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index bec61ea..2acc4e4 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -4036,7 +4036,6 @@
// Look through all of the overloaded functions, searching for one
// whose type matches exactly.
llvm::SmallPtrSet<FunctionDecl *, 4> Matches;
-
bool FoundNonTemplateFunction = false;
for (OverloadIterator FunEnd; Fun != FunEnd; ++Fun) {
// C++ [over.over]p3:
@@ -4106,15 +4105,8 @@
// C++ [over.over]p4:
// If more than one function is selected, [...]
- llvm::SmallVector<FunctionDecl *, 4> RemainingMatches;
typedef llvm::SmallPtrSet<FunctionDecl *, 4>::iterator MatchIter;
- if (FoundNonTemplateFunction) {
- // [...] any function template specializations in the set are
- // eliminated if the set also contains a non-template function, [...]
- for (MatchIter M = Matches.begin(), MEnd = Matches.end(); M != MEnd; ++M)
- if ((*M)->getPrimaryTemplate() == 0)
- RemainingMatches.push_back(*M);
- } else {
+ if (!FoundNonTemplateFunction) {
// [...] and any given function template specialization F1 is
// eliminated if the set contains a second function template
// specialization whose function template is more specialized
@@ -4125,45 +4117,23 @@
// two-pass algorithm (similar to the one used to identify the
// best viable function in an overload set) that identifies the
// best function template (if it exists).
- MatchIter Best = Matches.begin();
- MatchIter M = Best, MEnd = Matches.end();
- // Find the most specialized function.
- for (++M; M != MEnd; ++M)
- if (getMoreSpecializedTemplate((*M)->getPrimaryTemplate(),
- (*Best)->getPrimaryTemplate(),
- TPOC_Other)
- == (*M)->getPrimaryTemplate())
- Best = M;
-
- // Determine whether this function template is more specialized
- // that all of the others.
- bool Ambiguous = false;
- for (M = Matches.begin(); M != MEnd; ++M) {
- if (M != Best &&
- getMoreSpecializedTemplate((*M)->getPrimaryTemplate(),
- (*Best)->getPrimaryTemplate(),
- TPOC_Other)
- != (*Best)->getPrimaryTemplate()) {
- Ambiguous = true;
- break;
- }
- }
-
- // If one function template was more specialized than all of the
- // others, return it.
- if (!Ambiguous)
- return *Best;
-
- // We could not find a most-specialized function template, which
- // is equivalent to having a set of function templates with more
- // than one such template. So, we place all of the function
- // templates into the set of remaining matches and produce a
- // diagnostic below. FIXME: we could perform the quadratic
- // algorithm here, pruning the result set to limit the number of
- // candidates output later.
- RemainingMatches.append(Matches.begin(), Matches.end());
+ llvm::SmallVector<FunctionDecl *, 8> TemplateMatches(Matches.begin(),
+ Matches.end());
+ return getMostSpecialized(TemplateMatches.data(), TemplateMatches.size(),
+ TPOC_Other, From->getLocStart(),
+ PartialDiagnostic(0),
+ PartialDiagnostic(diag::err_addr_ovl_ambiguous)
+ << TemplateMatches[0]->getDeclName(),
+ PartialDiagnostic(diag::err_ovl_template_candidate));
}
+ // [...] any function template specializations in the set are
+ // eliminated if the set also contains a non-template function, [...]
+ llvm::SmallVector<FunctionDecl *, 4> RemainingMatches;
+ for (MatchIter M = Matches.begin(), MEnd = Matches.end(); M != MEnd; ++M)
+ if ((*M)->getPrimaryTemplate() == 0)
+ RemainingMatches.push_back(*M);
+
// [...] After such eliminations, if any, there shall remain exactly one
// selected function.
if (RemainingMatches.size() == 1)