Implement template instantiation for DeclStmt
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71818 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index 52daa5d..2dca993 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -441,6 +441,7 @@
// FIXME: Once we get closer to completion, replace these
// manually-written declarations with automatically-generated ones
// from clang/AST/StmtNodes.def.
+ OwningStmtResult VisitDeclStmt(DeclStmt *S);
OwningStmtResult VisitNullStmt(NullStmt *S);
OwningStmtResult VisitCompoundStmt(CompoundStmt *S);
OwningStmtResult VisitExpr(Expr *E);
@@ -454,6 +455,28 @@
};
}
+Sema::OwningStmtResult TemplateStmtInstantiator::VisitDeclStmt(DeclStmt *S) {
+ llvm::SmallVector<Decl *, 8> Decls;
+ for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
+ D != DEnd; ++D) {
+ Decl *Instantiated = SemaRef.InstantiateDecl(*D, SemaRef.CurContext,
+ TemplateArgs);
+ if (!Instantiated)
+ return SemaRef.StmtError();
+
+ Decls.push_back(Instantiated);
+ SemaRef.CurrentInstantiationScope->InstantiatedLocal(cast<VarDecl>(*D),
+ cast<VarDecl>(Instantiated));
+ }
+
+ return SemaRef.Owned(new (SemaRef.Context) DeclStmt(
+ DeclGroupRef::Create(SemaRef.Context,
+ &Decls[0],
+ Decls.size()),
+ S->getStartLoc(),
+ S->getEndLoc()));
+}
+
Sema::OwningStmtResult TemplateStmtInstantiator::VisitNullStmt(NullStmt *S) {
return SemaRef.Owned(new (SemaRef.Context) NullStmt(S->getSemiLoc()));
}