]> granicus.if.org Git - clang/commitdiff
Instantiate enclosing template parameter lists when instantiating friends.
authorJohn McCall <rjmccall@apple.com>
Tue, 19 Oct 2010 02:26:41 +0000 (02:26 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 19 Oct 2010 02:26:41 +0000 (02:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116789 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 57ea18809d997105d273197227e2acceb7af344f..5636647cda50ca044591a9a3ea14c7d369bb2283 100644 (file)
@@ -1276,6 +1276,20 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
       cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
   LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
 
+  // Instantiate enclosing template arguments for friends.
+  llvm::SmallVector<TemplateParameterList *, 4> TempParamLists;
+  unsigned NumTempParamLists = 0;
+  if (isFriend && (NumTempParamLists = D->getNumTemplateParameterLists())) {
+    TempParamLists.set_size(NumTempParamLists);
+    for (unsigned I = 0; I != NumTempParamLists; ++I) {
+      TemplateParameterList *TempParams = D->getTemplateParameterList(I);
+      TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
+      if (!InstParams)
+        return NULL;
+      TempParamLists[I] = InstParams;
+    }
+  }
+
   llvm::SmallVector<ParmVarDecl *, 4> Params;
   TypeSourceInfo *TInfo = D->getTypeSourceInfo();
   TInfo = SubstFunctionType(D, Params);
@@ -1402,6 +1416,11 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
   // out-of-line, the instantiation will have the same lexical
   // context (which will be a namespace scope) as the template.
   if (isFriend) {
+    if (NumTempParamLists)
+      Method->setTemplateParameterListsInfo(SemaRef.Context,
+                                            NumTempParamLists,
+                                            TempParamLists.data());
+
     Method->setLexicalDeclContext(Owner);
     Method->setObjectOfFriendDecl(true);
   } else if (D->isOutOfLine())
index 7d1ef7b2d39be41fd4189ec65a428b7e29dcbf12..63fd3df269000131614cd452feb7349a3892f9cc 100644 (file)
@@ -57,7 +57,7 @@ namespace test2 {
   };
 }
 
-// rdar://problem/8540527
+// Tests 3, 4 and 5 were all noted in <rdar://problem/8540527>.
 namespace test3 {
   template <class T> struct A {
     struct Inner {
@@ -92,3 +92,12 @@ namespace test4 {
     X<int>() += 1.0;
   }
 }
+
+namespace test5 {
+  template<template <class> class T> struct A {
+    template<template <class> class T> friend void A<T>::foo();
+  };
+
+  template <class> struct B {};
+  template class A<B>;
+}