[cfe-commits] r118454 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/class-template-decl.cpp
Nick Lewycky
nicholas at mxc.ca
Mon Nov 8 15:29:42 PST 2010
Author: nicholas
Date: Mon Nov 8 17:29:42 2010
New Revision: 118454
URL: http://llvm.org/viewvc/llvm-project?rev=118454&view=rev
Log:
Don't lose track of previous-declarations when instantiating a class template.
Fixes PR8001.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/class-template-decl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=118454&r1=118453&r2=118454&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Nov 8 17:29:42 2010
@@ -722,6 +722,15 @@
CXXRecordDecl *PrevDecl = 0;
ClassTemplateDecl *PrevClassTemplate = 0;
+ if (!isFriend && Pattern->getPreviousDeclaration()) {
+ DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
+ if (Found.first != Found.second) {
+ PrevClassTemplate = dyn_cast<ClassTemplateDecl>(*Found.first);
+ if (PrevClassTemplate)
+ PrevDecl = PrevClassTemplate->getTemplatedDecl();
+ }
+ }
+
// If this isn't a friend, then it's a member template, in which
// case we just want to build the instantiation in the
// specialization. If it is a friend, we want to build it in
@@ -836,7 +845,8 @@
// friend target decl?
} else {
Inst->setAccess(D->getAccess());
- Inst->setInstantiatedFromMemberTemplate(D);
+ if (!PrevClassTemplate)
+ Inst->setInstantiatedFromMemberTemplate(D);
}
// Trigger creation of the type for the instantiation.
Modified: cfe/trunk/test/SemaTemplate/class-template-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/class-template-decl.cpp?rev=118454&r1=118453&r2=118454&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/class-template-decl.cpp (original)
+++ cfe/trunk/test/SemaTemplate/class-template-decl.cpp Mon Nov 8 17:29:42 2010
@@ -56,3 +56,21 @@
}
template<typename T> class M::C3 { }; // expected-error{{out-of-line definition of 'C3' does not match any declaration in namespace 'M'}}
+
+namespace PR8001 {
+ template<typename T1>
+ struct Foo {
+ template<typename T2> class Bar;
+ typedef Bar<T1> Baz;
+
+ template<typename T2>
+ struct Bar {
+ Bar() {}
+ };
+ };
+
+ void pr8001() {
+ Foo<int>::Baz x;
+ Foo<int>::Bar<int> y(x);
+ }
+}
More information about the cfe-commits
mailing list