[cfe-commits] r95376 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/Parser/cxx-template-decl.cpp

Douglas Gregor dgregor at apple.com
Thu Feb 4 23:07:11 PST 2010


Author: dgregor
Date: Fri Feb  5 01:07:10 2010
New Revision: 95376

URL: http://llvm.org/viewvc/llvm-project?rev=95376&view=rev
Log:
Teach C++ name lookup that it's okay to look in a scope without a
context. This happens fairly rarely (which is why we got away with
this bug). Fixes PR6184, where we skipped over the template parameter
scope while tentatively parsing.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/Parser/cxx-template-decl.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=95376&r1=95375&r2=95376&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Feb  5 01:07:10 2010
@@ -649,12 +649,9 @@
 
   for (; S; S = S->getParent()) {
     DeclContext *Ctx = static_cast<DeclContext *>(S->getEntity());
-    if (!Ctx || Ctx->isTransparentContext())
+    if (Ctx && Ctx->isTransparentContext())
       continue;
 
-    assert(Ctx && Ctx->isFileContext() &&
-           "We should have been looking only at file context here already.");
-
     // Check whether the IdResolver has anything in this scope.
     bool Found = false;
     for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) {
@@ -668,16 +665,21 @@
       }
     }
 
-    // Look into context considering using-directives.
-    if (CppNamespaceLookup(R, Context, Ctx, UDirs))
-      Found = true;
+    if (Ctx) {
+      assert(Ctx->isFileContext() &&
+             "We should have been looking only at file context here already.");
+
+      // Look into context considering using-directives.
+      if (CppNamespaceLookup(R, Context, Ctx, UDirs))
+        Found = true;
+    }
 
     if (Found) {
       R.resolveKind();
       return true;
     }
 
-    if (R.isForRedeclaration() && !Ctx->isTransparentContext())
+    if (R.isForRedeclaration() && Ctx && !Ctx->isTransparentContext())
       return false;
   }
 

Modified: cfe/trunk/test/Parser/cxx-template-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-template-decl.cpp?rev=95376&r1=95375&r2=95376&view=diff

==============================================================================
--- cfe/trunk/test/Parser/cxx-template-decl.cpp (original)
+++ cfe/trunk/test/Parser/cxx-template-decl.cpp Fri Feb  5 01:07:10 2010
@@ -96,3 +96,13 @@
 
 // PR3844
 template <> struct S<int> { }; // expected-error{{explicit specialization of non-template struct 'S'}}
+
+namespace PR6184 {
+  namespace N {
+    template <typename T>
+    void bar(typename T::x);
+  }
+  
+  template <typename T>
+  void N::bar(typename T::x) { }
+}





More information about the cfe-commits mailing list