[cfe-commits] r116789 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.decls/temp.friend/p5.cpp
John McCall
rjmccall at apple.com
Mon Oct 18 19:26:41 PDT 2010
Author: rjmccall
Date: Mon Oct 18 21:26:41 2010
New Revision: 116789
URL: http://llvm.org/viewvc/llvm-project?rev=116789&view=rev
Log:
Instantiate enclosing template parameter lists when instantiating friends.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p5.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=116789&r1=116788&r2=116789&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Oct 18 21:26:41 2010
@@ -1276,6 +1276,20 @@
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 @@
// 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())
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=116789&r1=116788&r2=116789&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 Mon Oct 18 21:26:41 2010
@@ -57,7 +57,7 @@
};
}
-// 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 @@
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>;
+}
More information about the cfe-commits
mailing list