From: Douglas Gregor Date: Mon, 15 Mar 2010 15:26:48 +0000 (+0000) Subject: During C++ name lookup, use DeclContext::Equals() rather than X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbdf5e7d0b6f1f8d8c496c1a0ada6f706cddf100;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98546 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 0bdc6f54b7..6f8284458f 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -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 diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 615f2f1d84..6caeec620d 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -603,8 +603,7 @@ static std::pair findOuterContext(Scope *S) { for (Scope *OuterS = S->getParent(); OuterS; OuterS = OuterS->getParent()) { if (OuterS->getEntity()) { - Lexical - = static_cast(OuterS->getEntity())->getPrimaryContext(); + Lexical = static_cast(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(Ctx)) { if (Method->isInstanceMethod()) { diff --git a/test/CXX/temp/temp.res/temp.local/p8.cpp b/test/CXX/temp/temp.res/temp.local/p8.cpp index a90c78cd4b..5d9d50913f 100644 --- a/test/CXX/temp/temp.res/temp.local/p8.cpp +++ b/test/CXX/temp/temp.res/temp.local/p8.cpp @@ -23,7 +23,15 @@ namespace N { D d; } }; + + struct Y { + template void f(U); + }; } + + struct Y { + template void f(D); + }; } template @@ -32,3 +40,14 @@ void N::M::X::f(C, D) { C c; D d; } + +template +void N::M::Y::f(C) { + C c; +} + +template +void N::Y::f(D) { + D d; +} +