From d0e23ecdc2b40ff5aeb72adcfd33f7fa4d034ac6 Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 19 Oct 2010 02:26:41 +0000 Subject: Instantiate enclosing template parameter lists when instantiating friends. llvm-svn: 116789 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 19 +++++++++++++++++++ clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 57ea18809d9..5636647cda5 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1276,6 +1276,20 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, cast(Owner)->isDefinedOutsideFunctionOrMethod()); LocalInstantiationScope Scope(SemaRef, MergeWithParentScope); + // Instantiate enclosing template arguments for friends. + llvm::SmallVector 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 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()) diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp index 7d1ef7b2d39..63fd3df2690 100644 --- a/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp @@ -57,7 +57,7 @@ namespace test2 { }; } -// rdar://problem/8540527 +// Tests 3, 4 and 5 were all noted in . namespace test3 { template struct A { struct Inner { @@ -92,3 +92,12 @@ namespace test4 { X() += 1.0; } } + +namespace test5 { + template