Add TemplateArgument::CreatePackCopy() to create a new parameter pack
in ASTContext-allocated memory, copying the provided template
arguments. Use this new routine where we can. No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123289 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp
index 68e2332..6d6fee6 100644
--- a/lib/AST/TemplateBase.cpp
+++ b/lib/AST/TemplateBase.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/FoldingSet.h"
+#include <algorithm>
 
 using namespace clang;
 
@@ -28,6 +29,17 @@
 // TemplateArgument Implementation
 //===----------------------------------------------------------------------===//
 
+TemplateArgument TemplateArgument::CreatePackCopy(ASTContext &Context,
+                                                  const TemplateArgument *Args,
+                                                  unsigned NumArgs) {
+  if (NumArgs == 0)
+    return TemplateArgument(0, 0);
+  
+  TemplateArgument *Storage = new (Context) TemplateArgument [NumArgs];
+  std::copy(Args, Args + NumArgs, Storage);
+  return TemplateArgument(Storage, NumArgs);
+}
+
 bool TemplateArgument::isDependent() const {
   switch (getKind()) {
   case Null: