From b4850465b77f98dce508201c938b7222ed878331 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 14 May 2009 23:26:13 +0000 Subject: Introduce basic support for instantiating the definitions of member functions of class templates. Only compound statements and expression statements are currently implemented. llvm-svn: 71814 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'clang/lib/Sema/SemaTemplateInstantiateDecl.cpp') diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 02df5931a5b..eb006dc3f3e 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -572,6 +572,9 @@ TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, void Sema::InstantiateFunctionDefinition(FunctionDecl *Function) { // FIXME: make this work for function template specializations, too. + if (Function->isInvalidDecl()) + return; + // Find the function body that we'll be substituting. const FunctionDecl *PatternDecl = Function->getInstantiatedFromMemberFunction(); @@ -582,7 +585,23 @@ void Sema::InstantiateFunctionDefinition(FunctionDecl *Function) { if (!Pattern) return; - // FIXME: instantiate the pattern + // Introduce a new scope where local variable instantiations will be + // recorded. + LocalInstantiationScope Scope(*this); + + // Introduce the instantiated function parameters into the local + // instantiation scope. + for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) + Scope.InstantiatedLocal(PatternDecl->getParamDecl(I), + Function->getParamDecl(I)); + + // Instantiate the function body. + OwningStmtResult Body + = InstantiateStmt(Pattern, getTemplateInstantiationArgs(Function)); + if (Body.isInvalid()) + Function->setInvalidDecl(true); + else + Function->setBody(Body.takeAs()); } /// \brief Instantiate the definition of the given variable from its -- cgit v1.2.3