During C++ name lookup, use DeclContext::Equals() rather than

comparing DeclContext pointers, to avoid having to remember to call
getPrimaryContext() everywhere. This is the last part PR6594.

llvm-svn: 98546
This commit is contained in:
Douglas Gregor 2010-03-15 15:26:48 +00:00
parent 6623006249
commit ea16606fcd
3 changed files with 23 additions and 6 deletions

View File

@ -660,7 +660,7 @@ public:
/// \brief Determine whether this declaration context is equivalent
/// to the declaration context DC.
bool Equals(DeclContext *DC) {
return this->getPrimaryContext() == DC->getPrimaryContext();
return DC && this->getPrimaryContext() == DC->getPrimaryContext();
}
/// \brief Determine whether this declaration context encloses the

View File

@ -603,8 +603,7 @@ static std::pair<DeclContext *, bool> findOuterContext(Scope *S) {
for (Scope *OuterS = S->getParent(); OuterS;
OuterS = OuterS->getParent()) {
if (OuterS->getEntity()) {
Lexical
= static_cast<DeclContext *>(OuterS->getEntity())->getPrimaryContext();
Lexical = static_cast<DeclContext *>(OuterS->getEntity());
break;
}
}
@ -722,8 +721,7 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
if (SearchAfterTemplateScope)
OutsideOfTemplateParamDC = OuterCtx;
for (; Ctx && Ctx->getPrimaryContext() != OuterCtx;
Ctx = Ctx->getLookupParent()) {
for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) {
// We do not directly look into transparent contexts, since
// those entities will be found in the nearest enclosing
// non-transparent context.
@ -2307,7 +2305,7 @@ static void LookupVisibleDecls(Scope *S, LookupResult &Result,
Entity = (DeclContext *)S->getEntity();
DeclContext *OuterCtx = findOuterContext(S).first; // FIXME
for (DeclContext *Ctx = Entity; Ctx && Ctx->getPrimaryContext() != OuterCtx;
for (DeclContext *Ctx = Entity; Ctx && !Ctx->Equals(OuterCtx);
Ctx = Ctx->getLookupParent()) {
if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(Ctx)) {
if (Method->isInstanceMethod()) {

View File

@ -23,7 +23,15 @@ namespace N {
D d;
}
};
struct Y {
template<typename U> void f(U);
};
}
struct Y {
template<typename D> void f(D);
};
}
template<typename C>
@ -32,3 +40,14 @@ void N::M::X<C>::f(C, D) {
C c;
D d;
}
template<typename C>
void N::M::Y::f(C) {
C c;
}
template<typename D>
void N::Y::f(D) {
D d;
}