]> granicus.if.org Git - clang/commitdiff
Instantiate class template friends better; fixes PR5332.
authorDouglas Gregor <dgregor@apple.com>
Fri, 30 Oct 2009 21:07:27 +0000 (21:07 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 30 Oct 2009 21:07:27 +0000 (21:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85612 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CXX/temp/temp.decls/temp.friend/p5.cpp
test/SemaTemplate/friend-template.cpp

index 0b54533175aa9af630e560dbd5cb8d4335eeff18..f511eb15d2958c1d550671cba9299d4f720c0b0b 100644 (file)
@@ -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 
index f1142a4129b253121efa62f0ad256a53c65dd3af..74895c490623564ac49eac71ad713bc786f4ed48 100644 (file)
@@ -9,3 +9,5 @@ class B {
   template <class T> friend class A<T>::Member;
 };
 
+A<int> a;
+B b;
index 761c13076d2ab03a739c152d33591f49f252b11a..dc277f4657caaf174858eb85c0665d27992c3880 100644 (file)
@@ -54,6 +54,7 @@ struct X1 {
 template<typename U> void f2(U);
 
 X1<int> x1i;
+X0<int*> x0ip;
 
 template<> void f2(int);
 
@@ -62,3 +63,12 @@ template<> void f2(int);
 template<typename U> void f3(U);
 
 template<> void f3(int);
+
+// PR5332
+template <typename T>
+class Foo {
+  template <typename U>
+  friend class Foo;
+};
+
+Foo<int> foo;