*Recursively* set the context of a template parameter, so that we also

capture the template parameters of template template parameters.

llvm-svn: 127012
This commit is contained in:
Douglas Gregor 2011-03-04 18:32:38 +00:00
parent 5f45f6c014
commit 3c41bf740f
1 changed files with 15 additions and 17 deletions

View File

@ -95,6 +95,18 @@ unsigned TemplateParameterList::getDepth() const {
return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
}
static void AdoptTemplateParameterList(TemplateParameterList *Params,
DeclContext *Owner) {
for (TemplateParameterList::iterator P = Params->begin(),
PEnd = Params->end();
P != PEnd; ++P) {
(*P)->setDeclContext(Owner);
if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
}
}
//===----------------------------------------------------------------------===//
// RedeclarableTemplateDecl Implementation
//===----------------------------------------------------------------------===//
@ -165,12 +177,7 @@ FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
DeclarationName Name,
TemplateParameterList *Params,
NamedDecl *Decl) {
// Take ownership of the template parameters.
for (TemplateParameterList::iterator P = Params->begin(),
PEnd = Params->end();
P != PEnd; ++P)
(*P)->setDeclContext(cast<DeclContext>(Decl));
AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl);
}
@ -207,12 +214,7 @@ ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
TemplateParameterList *Params,
NamedDecl *Decl,
ClassTemplateDecl *PrevDecl) {
// Take ownership of the template parameters.
for (TemplateParameterList::iterator P = Params->begin(),
PEnd = Params->end();
P != PEnd; ++P)
(*P)->setDeclContext(cast<DeclContext>(Decl));
AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl);
New->setPreviousDeclaration(PrevDecl);
return New;
@ -633,11 +635,7 @@ ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber),
InstantiatedFromMember(0, false)
{
// Take ownership of the template parameters.
for (TemplateParameterList::iterator P = Params->begin(),
PEnd = Params->end();
P != PEnd; ++P)
(*P)->setDeclContext(this);
AdoptTemplateParameterList(Params, this);
}
ClassTemplatePartialSpecializationDecl *