]> granicus.if.org Git - clang/commitdiff
Link up member-class redeclarations during template instantiation.
authorJohn McCall <rjmccall@apple.com>
Tue, 15 Dec 2009 22:29:06 +0000 (22:29 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 15 Dec 2009 22:29:06 +0000 (22:29 +0000)
This test courtesy of LLVM.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-member-class.cpp

index 8d74bd76ca5ccbf29a07de83ec3ad3d2f0a3799c..69982be84b908d12d87eb9e3a9bc50e3171fdb6f 100644 (file)
@@ -645,6 +645,12 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
   CXXRecordDecl *PrevDecl = 0;
   if (D->isInjectedClassName())
     PrevDecl = cast<CXXRecordDecl>(Owner);
+  else if (D->getPreviousDeclaration()) {
+    NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getPreviousDeclaration(),
+                                                   TemplateArgs);
+    if (!Prev) return 0;
+    PrevDecl = cast<CXXRecordDecl>(Prev);
+  }
 
   CXXRecordDecl *Record
     = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner,
index ff0efd800f984b2b0ac148ad3907e7986641d41d..8a19d74cdde4ab4af8796cffc697d6a13fccf2de 100644 (file)
@@ -36,3 +36,17 @@ void test_instantiation(X<double>::C *x,
 X<void>::C *c3; // okay
 X<void>::D::E *e1; // okay
 X<void>::D::E e2; // expected-note{{in instantiation of member class 'struct X<void>::D::E' requested here}}
+
+// Redeclarations.
+namespace test1 {
+  template <typename T> struct Registry {
+    class node;
+    static node *Head;
+    class node {
+      node(int v) { Head = this; }
+    };
+  };
+  void test() {
+    Registry<int>::node node(0);
+  }
+}