[cfe-commits] r98546 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/Sema/SemaLookup.cpp test/CXX/temp/temp.res/temp.local/p8.cpp

Douglas Gregor dgregor at apple.com
Mon Mar 15 08:26:48 PDT 2010


Author: dgregor
Date: Mon Mar 15 10:26:48 2010
New Revision: 98546

URL: http://llvm.org/viewvc/llvm-project?rev=98546&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/CXX/temp/temp.res/temp.local/p8.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=98546&r1=98545&r2=98546&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Mon Mar 15 10:26:48 2010
@@ -660,7 +660,7 @@
   /// \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

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=98546&r1=98545&r2=98546&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Mar 15 10:26:48 2010
@@ -603,8 +603,7 @@
   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 @@
       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 @@
     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()) {

Modified: cfe/trunk/test/CXX/temp/temp.res/temp.local/p8.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.res/temp.local/p8.cpp?rev=98546&r1=98545&r2=98546&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.res/temp.local/p8.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.res/temp.local/p8.cpp Mon Mar 15 10:26:48 2010
@@ -23,7 +23,15 @@
         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 @@
   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;
+}
+





More information about the cfe-commits mailing list