Implicit instantiation for function template specializations.

For a FunctionDecl that has been instantiated due to template argument
deduction, we now store the primary template from which it was
instantiated and the deduced template arguments. From this
information, we can instantiate the body of the function template.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74232 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 95655d8..a05095f 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -645,16 +645,17 @@
 /// function.
 void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
                                          FunctionDecl *Function) {
-  // FIXME: make this work for function template specializations, too.
-
   if (Function->isInvalidDecl())
     return;
 
   assert(!Function->getBody(Context) && "Already instantiated!");
   
   // Find the function body that we'll be substituting.
-  const FunctionDecl *PatternDecl 
-    = Function->getInstantiatedFromMemberFunction();
+  const FunctionDecl *PatternDecl = 0;
+  if (FunctionTemplateDecl *Primary = Function->getPrimaryTemplate())
+    PatternDecl = Primary->getTemplatedDecl();
+  else 
+    PatternDecl = Function->getInstantiatedFromMemberFunction();
   Stmt *Pattern = 0;
   if (PatternDecl)
     Pattern = PatternDecl->getBody(Context, PatternDecl);