diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-06 22:05:37 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-06 22:05:37 +0000 |
commit | 5407920f82618114a66e92bf5dad280f42a4075c (patch) | |
tree | 2b2f9b5a738d6c78f9f8730452f72996bd0eedc8 /clang/lib/Sema/SemaLookup.cpp | |
parent | 9a5b242d3ca460a755599f867eb1d8903e8ee782 (diff) | |
download | bcm5719-llvm-5407920f82618114a66e92bf5dad280f42a4075c.tar.gz bcm5719-llvm-5407920f82618114a66e92bf5dad280f42a4075c.zip |
During name lookup, use redecl_iterator to walk over the redeclaration
chain to determine whether any declaration of the given entity is
visible, eliminating the redundant (and less efficient)
getPreviousDeclaration() implementation.
This tweak uncovered an omission in the handling of
RedeclarableTemplateDecl, where we weren't making sure to search for
additional redeclarations of a template in other module files. Things
would be cleaner if RedeclarableTemplateDecl actually used Redeclarable.
llvm-svn: 147687
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 7ee50e3a4c1..984184b9c98 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1053,26 +1053,6 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { return !R.empty(); } -/// \brief Retrieve the previous declaration of D. -static NamedDecl *getPreviousDeclaration(NamedDecl *D) { - if (TagDecl *TD = dyn_cast<TagDecl>(D)) - return TD->getPreviousDeclaration(); - if (VarDecl *VD = dyn_cast<VarDecl>(D)) - return VD->getPreviousDeclaration(); - if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) - return FD->getPreviousDeclaration(); - if (RedeclarableTemplateDecl *RTD = dyn_cast<RedeclarableTemplateDecl>(D)) - return RTD->getPreviousDeclaration(); - if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) - return TD->getPreviousDeclaration(); - if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) - return ID->getPreviousDeclaration(); - if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) - return PD->getPreviousDeclaration(); - - return 0; -} - /// \brief Retrieve the visible declaration corresponding to D, if any. /// /// This routine determines whether the declaration D is visible in the current @@ -1085,9 +1065,12 @@ static NamedDecl *getVisibleDecl(NamedDecl *D) { if (LookupResult::isVisible(D)) return D; - while ((D = getPreviousDeclaration(D))) { - if (LookupResult::isVisible(D)) - return D; + for (Decl::redecl_iterator RD = D->redecls_begin(), RDEnd = D->redecls_end(); + RD != RDEnd; ++RD) { + if (NamedDecl *ND = dyn_cast<NamedDecl>(*RD)) { + if (LookupResult::isVisible(ND)) + return ND; + } } return 0; |