diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/DeclCXX.cpp | 10 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 28 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 31 |
4 files changed, 45 insertions, 26 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 752218db04..bffa70f18e 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -420,13 +420,9 @@ OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, return new (C) OverloadedFunctionDecl(DC, N); } -void OverloadedFunctionDecl::addOverload(FunctionTemplateDecl *FTD) { - Functions.push_back(FTD); - - // An overloaded function declaration always has the location of - // the most-recently-added function declaration. - if (FTD->getLocation().isValid()) - this->setLocation(FTD->getLocation()); +void OverloadedFunctionDecl::addOverload(AnyFunctionDecl F) { + Functions.push_back(F); + this->setLocation(F.get()->getLocation()); } LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 0dd68feb96..a53e420db3 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -679,7 +679,7 @@ public: OR_Deleted ///< Overload resoltuion refers to a deleted function. }; - typedef llvm::SmallPtrSet<FunctionDecl *, 16> FunctionSet; + typedef llvm::SmallPtrSet<AnyFunctionDecl, 16> FunctionSet; typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet; typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index cc9e783f61..e99217ea57 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1604,9 +1604,17 @@ void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, for (LookupResult::iterator Op = Operators.begin(), OpEnd = Operators.end(); Op != OpEnd; ++Op) { - if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Op)) + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Op)) { if (IsAcceptableNonMemberOperatorCandidate(FD, T1, T2, Context)) Functions.insert(FD); // FIXME: canonical FD + } else if (FunctionTemplateDecl *FunTmpl + = dyn_cast<FunctionTemplateDecl>(*Op)) { + // FIXME: friend operators? + // FIXME: do we need to check IsAcceptableNonMemberOperatorCandidate, + // later? + if (!FunTmpl->getDeclContext()->isRecord()) + Functions.insert(FunTmpl); + } } } @@ -1649,11 +1657,10 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, // lookup (11.4). DeclContext::lookup_iterator I, E; for (llvm::tie(I, E) = (*NS)->lookup(Context, Name); I != E; ++I) { - FunctionDecl *Func = dyn_cast<FunctionDecl>(*I); - if (!Func) - break; - - Functions.insert(Func); + if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*I)) + Functions.insert(Func); + else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(*I)) + Functions.insert(FunTmpl); } } @@ -1662,11 +1669,10 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, for (llvm::tie(I, E) = Context.getTranslationUnitDecl()->lookup(Context, Name); I != E; ++I) { - FunctionDecl *Func = dyn_cast<FunctionDecl>(*I); - if (!Func) - break; - - Functions.insert(Func); + if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*I)) + Functions.insert(Func); + else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(*I)) + Functions.insert(FunTmpl); } } } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index fcc155750c..e240c04e5d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -2161,9 +2161,15 @@ void Sema::AddFunctionCandidates(const FunctionSet &Functions, bool SuppressUserConversions) { for (FunctionSet::const_iterator F = Functions.begin(), FEnd = Functions.end(); - F != FEnd; ++F) - AddOverloadCandidate(*F, Args, NumArgs, CandidateSet, - SuppressUserConversions); + F != FEnd; ++F) { + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*F)) + AddOverloadCandidate(FD, Args, NumArgs, CandidateSet, + SuppressUserConversions); + else + AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*F), Args, + NumArgs, CandidateSet, + SuppressUserConversions); + } } /// AddMethodCandidate - Adds the given C++ member function to the set @@ -3405,8 +3411,11 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(), CandEnd = CandidateSet.end(); Cand != CandEnd; ++Cand) - if (Cand->Function) + if (Cand->Function) { Functions.insert(Cand->Function); + if (FunctionTemplateDecl *FunTmpl = Cand->Function->getPrimaryTemplate()) + Functions.insert(FunTmpl); + } ArgumentDependentLookup(Name, Args, NumArgs, Functions); @@ -3415,15 +3424,23 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(), CandEnd = CandidateSet.end(); Cand != CandEnd; ++Cand) - if (Cand->Function) + if (Cand->Function) { Functions.erase(Cand->Function); + if (FunctionTemplateDecl *FunTmpl = Cand->Function->getPrimaryTemplate()) + Functions.erase(FunTmpl); + } // For each of the ADL candidates we found, add it to the overload // set. for (FunctionSet::iterator Func = Functions.begin(), FuncEnd = Functions.end(); - Func != FuncEnd; ++Func) - AddOverloadCandidate(*Func, Args, NumArgs, CandidateSet); + Func != FuncEnd; ++Func) { + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Func)) + AddOverloadCandidate(FD, Args, NumArgs, CandidateSet); + else + AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*Func), Args, + NumArgs, CandidateSet); + } } /// isBetterOverloadCandidate - Determines whether the first overload |