[cfe-commits] r82844 - /cfe/trunk/lib/Sema/SemaOverload.cpp
Douglas Gregor
dgregor at apple.com
Fri Sep 25 20:56:18 PDT 2009
Author: dgregor
Date: Fri Sep 25 22:56:17 2009
New Revision: 82844
URL: http://llvm.org/viewvc/llvm-project?rev=82844&view=rev
Log:
Yet another simplifying use of Sema::getMostSpecialized
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=82844&r1=82843&r2=82844&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Sep 25 22:56:17 2009
@@ -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)
More information about the cfe-commits
mailing list