diff options
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 1a47340d69a..5df0a43621e 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4546,8 +4546,11 @@ bool CorrectionCandidateCallback::ValidateCandidate(const TypoCorrection &candid } FunctionCallFilterCCC::FunctionCallFilterCCC(Sema &SemaRef, unsigned NumArgs, - bool HasExplicitTemplateArgs) - : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs) { + bool HasExplicitTemplateArgs, + bool AllowNonStaticMethods) + : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs), + AllowNonStaticMethods(AllowNonStaticMethods), + CurContext(SemaRef.CurContext) { WantTypeSpecifiers = SemaRef.getLangOpts().CPlusPlus; WantRemainingKeywords = false; } @@ -4576,9 +4579,28 @@ bool FunctionCallFilterCCC::ValidateCandidate(const TypoCorrection &candidate) { return true; } } - if (FD && FD->getNumParams() >= NumArgs && - FD->getMinRequiredArguments() <= NumArgs) - return true; + + // Skip the current candidate if it is not a FunctionDecl or does not accept + // the current number of arguments. + if (!FD || !(FD->getNumParams() >= NumArgs && + FD->getMinRequiredArguments() <= NumArgs)) + continue; + + // If the current candidate is a non-static C++ method and non-static + // methods are being excluded, then skip the candidate unless the current + // DeclContext is a method in the same class or a descendent class of the + // candidate's parent class. + if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { + if (!AllowNonStaticMethods && !MD->isStatic()) { + CXXMethodDecl *CurMD = dyn_cast_or_null<CXXMethodDecl>(CurContext); + CXXRecordDecl *CurRD = + CurMD ? CurMD->getParent()->getCanonicalDecl() : 0; + CXXRecordDecl *RD = MD->getParent()->getCanonicalDecl(); + if (!CurRD || (CurRD != RD && !CurRD->isDerivedFrom(RD))) + continue; + } + } + return true; } return false; } |