Set access properly on instantiated friend class template declarations.
Fixes PR6752.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100806 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index e469046..1ac854c 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -753,7 +753,13 @@
                                 D->getIdentifier(), InstParams, RecordInst,
                                 PrevClassTemplate);
   RecordInst->setDescribedClassTemplate(Inst);
+
   if (isFriend) {
+    if (PrevClassTemplate)
+      Inst->setAccess(PrevClassTemplate->getAccess());
+    else
+      Inst->setAccess(D->getAccess());
+
     Inst->setObjectOfFriendDecl(PrevClassTemplate != 0);
     // TODO: do we want to track the instantiation progeny of this
     // friend target decl?
@@ -765,14 +771,13 @@
   // Trigger creation of the type for the instantiation.
   SemaRef.Context.getInjectedClassNameType(RecordInst,
                   Inst->getInjectedClassNameSpecialization(SemaRef.Context));
-  
+
   // Finish handling of friends.
   if (isFriend) {
     DC->makeDeclVisibleInContext(Inst, /*Recoverable*/ false);
     return Inst;
   }
   
-  Inst->setAccess(D->getAccess());
   Owner->addDecl(Inst);
   
   // First, we sort the partial specializations by location, so 
diff --git a/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/test/CXX/temp/temp.decls/temp.friend/p1.cpp
index 57c7102..597e06d 100644
--- a/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ b/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -238,3 +238,16 @@
 
   template A<int> bar<int>(const int *, const A<int> &); // expected-note {{in instantiation}}
 }
+
+// PR6752: this shouldn't crash.
+namespace test11 {
+  struct Foo {
+    template<class A>
+    struct IteratorImpl {
+      template<class T> friend class IteratorImpl;
+    };
+  };
+
+  template struct Foo::IteratorImpl<int>;
+  template struct Foo::IteratorImpl<long>;  
+}