diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-02 21:35:47 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-02 21:35:47 +0000 |
commit | d863517ab7e936cbc3244a0fc431c8b672f5ece4 (patch) | |
tree | f31d615998370f7144daca39cc2d1e096d4ed6af /lib/Sema/SemaDecl.cpp | |
parent | 81922f01352aceeb923c0c3cc8c96b6527322384 (diff) |
Add iterators to LookupResult, allowing one to iterate over the
non-ambiguous name lookup results without allocating any memory, e.g.,
for sets of overloaded functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63549 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index fe7ab92b6a..d03879e907 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1666,35 +1666,22 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, << D.getCXXScopeSpec().getRange(); InvalidDecl = true; - PrevDecl = LookupQualifiedName(DC, Name, LookupOrdinaryName); - if (!PrevDecl) { - // Nothing to suggest. - } else if (OverloadedFunctionDecl *Ovl - = dyn_cast<OverloadedFunctionDecl>(PrevDecl)) { - for (OverloadedFunctionDecl::function_iterator - Func = Ovl->function_begin(), - FuncEnd = Ovl->function_end(); - Func != FuncEnd; ++Func) { - if (isNearlyMatchingMemberFunction(Context, *Func, NewFD)) - Diag((*Func)->getLocation(), diag::note_member_def_close_match); - - } - } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(PrevDecl)) { - // Suggest this no matter how mismatched it is; it's the only - // thing we have. - unsigned diag; - if (isNearlyMatchingMemberFunction(Context, Method, NewFD)) - diag = diag::note_member_def_close_match; - else if (Method->getBody()) - diag = diag::note_previous_definition; - else - diag = diag::note_previous_declaration; - Diag(Method->getLocation(), diag); + LookupResult Prev = LookupQualifiedName(DC, Name, LookupOrdinaryName, + true); + assert(!Prev.isAmbiguous() && + "Cannot have an ambiguity in previous-declaration lookup"); + for (LookupResult::iterator Func = Prev.begin(), FuncEnd = Prev.end(); + Func != FuncEnd; ++Func) { + if (isa<CXXMethodDecl>(*Func) && + isNearlyMatchingMemberFunction(Context, cast<FunctionDecl>(*Func), + NewFD)) + Diag((*Func)->getLocation(), diag::note_member_def_close_match); } - + PrevDecl = 0; } } + // Handle attributes. We need to have merged decls when handling attributes // (for example to check for conflicts, etc). ProcessDeclAttributes(NewFD, D); |