Cope with explicitly-specified function template arguments when there
are fewer template arguments than there are template parameters for
that function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74578 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index ff01e41..3bc1cf9 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -584,6 +584,15 @@
if (T->getDepth() == 0) {
// Replace the template type parameter with its corresponding
// template argument.
+
+ // If the corresponding template argument is NULL or doesn't exist, it's
+ // because we are performing instantiation from explicitly-specified
+ // template arguments in a function template class, but there were some
+ // arguments left unspecified.
+ if (T->getIndex() >= TemplateArgs.size() ||
+ TemplateArgs[T->getIndex()].isNull())
+ return QualType(T, 0); // Would be nice to keep the original type here
+
assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type &&
"Template argument kind mismatch");
return TemplateArgs[T->getIndex()].getAsType();