Implement template argument deduction for pack expansions whose
pattern is a template argument, which involves repeatedly deducing
template arguments using the pattern of the pack expansion, then
bundling the resulting deductions into an argument pack.

We can now handle a variety of simple list-handling metaprograms using
variadic templates. See, e.g., the new "count" metaprogram.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122439 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp
index bfc834f..04e8a38 100644
--- a/lib/AST/TemplateBase.cpp
+++ b/lib/AST/TemplateBase.cpp
@@ -191,6 +191,28 @@
   return false;
 }
 
+TemplateArgument TemplateArgument::getPackExpansionPattern() const {
+  assert(isPackExpansion());
+  
+  switch (getKind()) {
+    case Type:
+      return getAsType()->getAs<PackExpansionType>()->getPattern();
+      
+    case Expression:
+    case Template:
+      // FIXME: Variadic templates.
+      llvm_unreachable("Expression and template pack expansions unsupported");
+      
+    case Declaration:
+    case Integral:
+    case Pack:
+    case Null:
+      return TemplateArgument();
+  }
+  
+  return TemplateArgument();
+}
+
 void TemplateArgument::print(const PrintingPolicy &Policy, 
                              llvm::raw_ostream &Out) const {
   switch (getKind()) {