[cfe-commits] r99657 - in /cfe/trunk: lib/AST/Decl.cpp test/SemaTemplate/instantiate-member-class.cpp

John McCall rjmccall at apple.com
Fri Mar 26 14:56:38 PDT 2010


Author: rjmccall
Date: Fri Mar 26 16:56:38 2010
New Revision: 99657

URL: http://llvm.org/viewvc/llvm-project?rev=99657&view=rev
Log:
Properly account for redeclarations when explicitly instantiating class templates.
What happens here is that we actually turn the first declaration into a
definition, regardless of whether it was actually originally a definition,
and furthermore we do this all after we've instantiated all the declarations.
This exposes a bug in my DefinitionData patch where it was only setting the
DefinitionData for previous declarations, not future declarations.
Fortunately, there's an iterator for that.


Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-member-class.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=99657&r1=99656&r2=99657&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Mar 26 16:56:38 2010
@@ -1413,10 +1413,8 @@
     CXXRecordDecl *D = cast<CXXRecordDecl>(this);
     struct CXXRecordDecl::DefinitionData *Data = 
       new (getASTContext()) struct CXXRecordDecl::DefinitionData(D);
-    do {
-      D->DefinitionData = Data;
-      D = cast_or_null<CXXRecordDecl>(D->getPreviousDeclaration());
-    } while (D);
+    for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I)
+      cast<CXXRecordDecl>(*I)->DefinitionData = Data;
   }
 }
 

Modified: cfe/trunk/test/SemaTemplate/instantiate-member-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-member-class.cpp?rev=99657&r1=99656&r2=99657&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-member-class.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-member-class.cpp Fri Mar 26 16:56:38 2010
@@ -50,3 +50,33 @@
     Registry<int>::node node(0);
   }
 }
+
+// Redeclarations during explicit instantiations.
+namespace test2 {
+  template <typename T> class A {
+    class Foo;
+    class Foo {
+      int foo();
+    };
+  };
+  template class A<int>;
+
+  template <typename T> class B {
+    class Foo;
+    class Foo {
+      typedef int X;
+    };
+    typename Foo::X x;
+    class Foo;
+  };
+  template class B<int>;
+
+  template <typename T> class C {
+    class Foo;
+    class Foo;
+  };
+  template <typename T> class C<T>::Foo {
+    int x;
+  };
+  template class C<int>;
+}





More information about the cfe-commits mailing list