[cfe-commits] r85612 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.decls/temp.friend/p5.cpp test/SemaTemplate/friend-template.cpp

Douglas Gregor dgregor at apple.com
Fri Oct 30 14:07:27 PDT 2009


Author: dgregor
Date: Fri Oct 30 16:07:27 2009
New Revision: 85612

URL: http://llvm.org/viewvc/llvm-project?rev=85612&view=rev
Log:
Instantiate class template friends better; fixes PR5332.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p5.cpp
    cfe/trunk/test/SemaTemplate/friend-template.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=85612&r1=85611&r2=85612&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Oct 30 16:07:27 2009
@@ -425,12 +425,19 @@
     = 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 

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p5.cpp?rev=85612&r1=85611&r2=85612&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p5.cpp Fri Oct 30 16:07:27 2009
@@ -9,3 +9,5 @@
   template <class T> friend class A<T>::Member;
 };
 
+A<int> a;
+B b;

Modified: cfe/trunk/test/SemaTemplate/friend-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/friend-template.cpp?rev=85612&r1=85611&r2=85612&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/friend-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/friend-template.cpp Fri Oct 30 16:07:27 2009
@@ -54,6 +54,7 @@
 template<typename U> void f2(U);
 
 X1<int> x1i;
+X0<int*> x0ip;
 
 template<> void f2(int);
 
@@ -62,3 +63,12 @@
 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;





More information about the cfe-commits mailing list