When default-initializing a TemplateArgumentLocInfo, make sure that we
initialize *all* of the bits to zero. Also, when the pattern of a
template argument pack expansion, make sure to set the ellipsis
location along all paths.
This should clear up the valgrind failure that popped up in Clang.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122931 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/TemplateBase.h b/include/clang/AST/TemplateBase.h
index 7f3e591..22ca164 100644
--- a/include/clang/AST/TemplateBase.h
+++ b/include/clang/AST/TemplateBase.h
@@ -330,7 +330,7 @@
};
public:
- TemplateArgumentLocInfo() : Expression(0) {}
+ TemplateArgumentLocInfo();
TemplateArgumentLocInfo(TypeSourceInfo *TInfo) : Declarator(TInfo) {}
diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h
index 81ece17..3480681 100644
--- a/include/clang/AST/TypeLoc.h
+++ b/include/clang/AST/TypeLoc.h
@@ -1115,8 +1115,11 @@
const TemplateArgument *Args,
TemplateArgumentLocInfo *ArgInfos,
SourceLocation Loc) {
- for (unsigned i = 0, e = NumArgs; i != e; ++i)
+ for (unsigned i = 0, e = NumArgs; i != e; ++i) {
+ // FIXME: We can generate better location info here for type arguments,
+ // template template arguments, and template template pack expansions (?).
ArgInfos[i] = TemplateArgumentLocInfo();
+ }
}
unsigned getExtraLocalDataSize() const {
diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp
index de5531f..68e2332 100644
--- a/lib/AST/TemplateBase.cpp
+++ b/lib/AST/TemplateBase.cpp
@@ -292,6 +292,10 @@
// TemplateArgumentLoc Implementation
//===----------------------------------------------------------------------===//
+TemplateArgumentLocInfo::TemplateArgumentLocInfo() {
+ memset(this, 0, sizeof(TemplateArgumentLocInfo));
+}
+
SourceRange TemplateArgumentLoc::getSourceRange() const {
switch (Argument.getKind()) {
case TemplateArgument::Expression:
@@ -362,11 +366,15 @@
}
case TemplateArgument::Expression: {
- Expr *Pattern = cast<PackExpansionExpr>(Argument.getAsExpr())->getPattern();
+ PackExpansionExpr *Expansion
+ = cast<PackExpansionExpr>(Argument.getAsExpr());
+ Expr *Pattern = Expansion->getPattern();
+ Ellipsis = Expansion->getEllipsisLoc();
return TemplateArgumentLoc(Pattern, Pattern);
}
case TemplateArgument::TemplateExpansion:
+ Ellipsis = getTemplateEllipsisLoc();
return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
getTemplateQualifierRange(),
getTemplateNameLoc());