]> granicus.if.org Git - clang/commitdiff
Set access properly on instantiated friend class template declarations.
authorJohn McCall <rjmccall@apple.com>
Thu, 8 Apr 2010 20:25:50 +0000 (20:25 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 8 Apr 2010 20:25:50 +0000 (20:25 +0000)
Fixes PR6752.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100806 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CXX/temp/temp.decls/temp.friend/p1.cpp

index e4690466d30ae58e2e41d6a630f7e03deef1de2e..1ac854c770cb82a394afc7418bed364f51ef959f 100644 (file)
@@ -753,7 +753,13 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
                                 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 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   // 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 
index 57c71027b6537b8b4e1161e957a01295b4128baa..597e06d292bcfa50be86f44a3cc2524f14179b66 100644 (file)
@@ -238,3 +238,16 @@ namespace test10 {
 
   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>;  
+}