]> granicus.if.org Git - clang/commitdiff
*Recursively* set the context of a template parameter, so that we also
authorDouglas Gregor <dgregor@apple.com>
Fri, 4 Mar 2011 18:32:38 +0000 (18:32 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 4 Mar 2011 18:32:38 +0000 (18:32 +0000)
capture the template parameters of template template parameters.

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

lib/AST/DeclTemplate.cpp

index 266d913ff4bd07e245751dce76c726bf0889a791..1ef47b9158b7c3b21d973d1978ede8caaf590cd5 100644 (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 *