mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 19:26:06 +00:00
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. llvm-svn: 123289
This commit is contained in:
parent
12cc296bd4
commit
74c6d19c1f
@ -191,6 +191,12 @@ public:
|
|||||||
getAsIntegral()->~APSInt();
|
getAsIntegral()->~APSInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Create a new template argument pack by copying the given set of
|
||||||
|
/// template arguments.
|
||||||
|
static TemplateArgument CreatePackCopy(ASTContext &Context,
|
||||||
|
const TemplateArgument *Args,
|
||||||
|
unsigned NumArgs);
|
||||||
|
|
||||||
/// \brief Return the kind of stored template argument.
|
/// \brief Return the kind of stored template argument.
|
||||||
ArgKind getKind() const { return (ArgKind)Kind; }
|
ArgKind getKind() const { return (ArgKind)Kind; }
|
||||||
|
|
||||||
|
@ -338,11 +338,8 @@ ClassTemplateDecl::getInjectedClassNameSpecialization() {
|
|||||||
Arg = TemplateArgument(TemplateName(TTP), TTP->isParameterPack());
|
Arg = TemplateArgument(TemplateName(TTP), TTP->isParameterPack());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*Param)->isTemplateParameterPack()) {
|
if ((*Param)->isTemplateParameterPack())
|
||||||
TemplateArgument *Pack = new (Context) TemplateArgument [1];
|
Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
|
||||||
*Pack = Arg;
|
|
||||||
Arg = TemplateArgument(Pack, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TemplateArgs.push_back(Arg);
|
TemplateArgs.push_back(Arg);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "clang/AST/TypeLoc.h"
|
#include "clang/AST/TypeLoc.h"
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "llvm/ADT/FoldingSet.h"
|
#include "llvm/ADT/FoldingSet.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
@ -28,6 +29,17 @@ using namespace clang;
|
|||||||
// TemplateArgument Implementation
|
// 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 {
|
bool TemplateArgument::isDependent() const {
|
||||||
switch (getKind()) {
|
switch (getKind()) {
|
||||||
case Null:
|
case Null:
|
||||||
|
@ -2556,13 +2556,12 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
|
|||||||
if ((*Param)->isTemplateParameterPack()) {
|
if ((*Param)->isTemplateParameterPack()) {
|
||||||
if (PartialTemplateArgs && ArgumentPack.empty()) {
|
if (PartialTemplateArgs && ArgumentPack.empty()) {
|
||||||
Converted.push_back(TemplateArgument());
|
Converted.push_back(TemplateArgument());
|
||||||
} else if (ArgumentPack.empty()) {
|
} else if (ArgumentPack.empty())
|
||||||
Converted.push_back(TemplateArgument(0, 0));
|
Converted.push_back(TemplateArgument(0, 0));
|
||||||
} else {
|
else {
|
||||||
TemplateArgument *PackedArgs
|
Converted.push_back(TemplateArgument::CreatePackCopy(Context,
|
||||||
= new (Context) TemplateArgument [ArgumentPack.size()];
|
ArgumentPack.data(),
|
||||||
std::copy(ArgumentPack.begin(), ArgumentPack.end(), PackedArgs);
|
ArgumentPack.size()));
|
||||||
Converted.push_back(TemplateArgument(PackedArgs, ArgumentPack.size()));
|
|
||||||
ArgumentPack.clear();
|
ArgumentPack.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1726,12 +1726,9 @@ static bool ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the resulting argument pack.
|
// Create the resulting argument pack.
|
||||||
TemplateArgument *PackedArgs = 0;
|
Output.push_back(TemplateArgument::CreatePackCopy(S.Context,
|
||||||
if (!PackedArgsBuilder.empty()) {
|
PackedArgsBuilder.data(),
|
||||||
PackedArgs = new (S.Context) TemplateArgument[PackedArgsBuilder.size()];
|
PackedArgsBuilder.size()));
|
||||||
std::copy(PackedArgsBuilder.begin(), PackedArgsBuilder.end(), PackedArgs);
|
|
||||||
}
|
|
||||||
Output.push_back(TemplateArgument(PackedArgs, PackedArgsBuilder.size()));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user