Template instantiation for function types

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65668 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index f864a50..f4653c1 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -65,7 +65,7 @@
 QualType 
 TemplateTypeInstantiator::InstantiateBuiltinType(const BuiltinType *T,
                                                  unsigned Quals) const {
-  assert(false && "BuiltinType is never dependent and cannot be instantiated");
+  assert(false && "Builtin types are not dependent and cannot be instantiated");
   return QualType(T, Quals);
 }
 
@@ -191,17 +191,32 @@
 TemplateTypeInstantiator::
 InstantiateFunctionProtoType(const FunctionProtoType *T,
                              unsigned Quals) const {
-  // FIXME: Implement this
-  assert(false && "Cannot instantiate FunctionProtoType yet");
-  return QualType();
+  QualType ResultType = Instantiate(T->getResultType());
+  if (ResultType.isNull())
+    return ResultType;
+
+  llvm::SmallVector<QualType, 16> ParamTypes;
+  for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(),
+                                         ParamEnd = T->arg_type_end(); 
+       Param != ParamEnd; ++Param) {
+    QualType P = Instantiate(*Param);
+    if (P.isNull())
+      return P;
+
+    ParamTypes.push_back(P);
+  }
+
+  return SemaRef.BuildFunctionType(ResultType, &ParamTypes[0], 
+                                   ParamTypes.size(),
+                                   T->isVariadic(), T->getTypeQuals(),
+                                   Loc, Entity);
 }
 
 QualType 
 TemplateTypeInstantiator::
 InstantiateFunctionNoProtoType(const FunctionNoProtoType *T,
                                unsigned Quals) const {
-  // FIXME: Implement this
-  assert(false && "Cannot instantiate FunctionNoProtoType yet");
+  assert(false && "Functions without prototypes cannot be dependent.");
   return QualType();
 }