]> granicus.if.org Git - clang/commitdiff
Teach C++ name lookup that it's okay to look in a scope without a
authorDouglas Gregor <dgregor@apple.com>
Fri, 5 Feb 2010 07:07:10 +0000 (07:07 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 5 Feb 2010 07:07:10 +0000 (07:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95376 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLookup.cpp
test/Parser/cxx-template-decl.cpp

index af1b8a276efc4b3fd7d20ee637f3ab7a29f23513..3c8ab435a860b898b965fdbc5c977e248ad3e936 100644 (file)
@@ -649,12 +649,9 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
 
   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 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
       }
     }
 
-    // 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;
   }
 
index 5cb84a63069bd412d3e706ba56d45c2100794397..3f8f1ec9d0be9f011808e8c09daf99acf3006c22 100644 (file)
@@ -96,3 +96,13 @@ void f2() {
 
 // 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) { }
+}