[cfe-commits] r122361 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/instantiate-local-class.cpp

Douglas Gregor dgregor at apple.com
Tue Dec 21 13:22:52 PST 2010


Author: dgregor
Date: Tue Dec 21 15:22:51 2010
New Revision: 122361

URL: http://llvm.org/viewvc/llvm-project?rev=122361&view=rev
Log:
When searching for the instantiation of a locally-scoped tag
declaration, also look for an instantiation of its previous
declarations. Fixes PR8801.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=122361&r1=122360&r2=122361&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Dec 21 15:22:51 2010
@@ -1735,11 +1735,21 @@
   for (LocalInstantiationScope *Current = this; Current; 
        Current = Current->Outer) {
     // Check if we found something within this scope.
-    llvm::DenseMap<const Decl *, Decl *>::iterator Found
-      = Current->LocalDecls.find(D);
-    if (Found != Current->LocalDecls.end())
-      return Found->second;
-   
+    const Decl *CheckD = D;
+    do {
+      llvm::DenseMap<const Decl *, Decl *>::iterator Found
+        = Current->LocalDecls.find(CheckD);
+      if (Found != Current->LocalDecls.end())
+        return Found->second;
+      
+      // If this is a tag declaration, it's possible that we need to look for
+      // a previous declaration.
+      if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
+        CheckD = Tag->getPreviousDeclaration();
+      else
+        CheckD = 0;
+    } while (CheckD);
+    
     // If we aren't combined with our outer scope, we're done. 
     if (!Current->CombineWithOuterScope)
       break;

Modified: cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp?rev=122361&r1=122360&r2=122361&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp Tue Dec 21 15:22:51 2010
@@ -50,3 +50,16 @@
   struct S { };
   void test() { f<S>(); }
 }
+
+namespace PR8801 {
+  template<typename T>
+  void foo() {
+    class X;
+    int (X::*pmf)(T) = 0;
+    class X : public T { };
+  }
+
+  struct Y { };
+
+  template void foo<Y>();
+}





More information about the cfe-commits mailing list