Introduce basic support for instantiating the definitions of member
functions of class templates. Only compound statements and expression
statements are currently implemented.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71814 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 02df593..eb006dc 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -572,6 +572,9 @@
 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 @@
   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<Stmt>());
 }
 
 /// \brief Instantiate the definition of the given variable from its