Properly rebuild pack expansions whose pattern is a non-type template
argument. As part of this, be more careful when determining if there
are any parameter packs that cannot be expanded.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122776 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp
index 828d2a3..a3e308f 100644
--- a/lib/Sema/SemaTemplateVariadic.cpp
+++ b/lib/Sema/SemaTemplateVariadic.cpp
@@ -428,7 +428,8 @@
     // If we don't have a template argument at this depth/index, then we 
     // cannot expand the pack expansion. Make a note of this, but we still 
     // want to check any parameter packs we *do* have arguments for.
-    if (!TemplateArgs.hasTemplateArgument(Depth, Index)) {
+    if (Depth >= TemplateArgs.getNumLevels() ||
+        !TemplateArgs.hasTemplateArgument(Depth, Index)) {
       ShouldExpand = false;
       continue;
     }