From e8c01bdb56549adcecd71ce39160eea54b2c51c8 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 30 Oct 2009 21:07:27 +0000 Subject: [PATCH] Instantiate class template friends better; fixes PR5332. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85612 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 ++++++++- test/CXX/temp/temp.decls/temp.friend/p5.cpp | 2 ++ test/SemaTemplate/friend-template.cpp | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 0b54533175..f511eb15d2 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -425,12 +425,19 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { = ClassTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), InstParams, RecordInst, 0); RecordInst->setDescribedClassTemplate(Inst); - Inst->setAccess(D->getAccess()); + if (D->getFriendObjectKind()) + Inst->setObjectOfFriendDecl(true); + else + Inst->setAccess(D->getAccess()); Inst->setInstantiatedFromMemberTemplate(D); // Trigger creation of the type for the instantiation. SemaRef.Context.getTypeDeclType(RecordInst); + // We're done with friends now. + if (Inst->getFriendObjectKind()) + return Inst; + Owner->addDecl(Inst); // First, we sort the partial specializations by location, so diff --git a/test/CXX/temp/temp.decls/temp.friend/p5.cpp b/test/CXX/temp/temp.decls/temp.friend/p5.cpp index f1142a4129..74895c4906 100644 --- a/test/CXX/temp/temp.decls/temp.friend/p5.cpp +++ b/test/CXX/temp/temp.decls/temp.friend/p5.cpp @@ -9,3 +9,5 @@ class B { template friend class A::Member; }; +A a; +B b; diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 761c13076d..dc277f4657 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -54,6 +54,7 @@ struct X1 { template void f2(U); X1 x1i; +X0 x0ip; template<> void f2(int); @@ -62,3 +63,12 @@ template<> void f2(int); template void f3(U); template<> void f3(int); + +// PR5332 +template +class Foo { + template + friend class Foo; +}; + +Foo foo; -- 2.40.0