diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-01-03 17:17:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-01-03 17:17:50 +0000 |
commit | be230c36e32142cbdcdbe9c97511d097beeecbab (patch) | |
tree | a9c32a8f84720ac278c7bd11ab45b5d12859a7a0 /lib/AST/TemplateBase.cpp | |
parent | 9917401b32f26b16ae6053d07903ac147b64a43b (diff) |
Implement support for pack expansions whose pattern is a non-type
template argument (described by an expression, of course). For
example:
template<int...> struct int_tuple { };
template<int ...Values>
struct square {
typedef int_tuple<(Values*Values)...> type;
};
It also lays the foundation for pack expansions in an initializer-list.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122751 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/TemplateBase.cpp')
-rw-r--r-- | lib/AST/TemplateBase.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp index 04e8a389cf..c971519961 100644 --- a/lib/AST/TemplateBase.cpp +++ b/lib/AST/TemplateBase.cpp @@ -17,6 +17,7 @@ #include "clang/AST/DeclBase.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" #include "clang/AST/TypeLoc.h" #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/FoldingSet.h" @@ -72,15 +73,14 @@ bool TemplateArgument::isPackExpansion() const { return false; case Type: - return llvm::isa<PackExpansionType>(getAsType()); + return isa<PackExpansionType>(getAsType()); case Template: // FIXME: Template template pack expansions. break; case Expression: - // FIXME: Expansion pack expansions. - break; + return isa<PackExpansionExpr>(getAsExpr()); } return false; @@ -199,9 +199,11 @@ TemplateArgument TemplateArgument::getPackExpansionPattern() const { return getAsType()->getAs<PackExpansionType>()->getPattern(); case Expression: + return cast<PackExpansionExpr>(getAsExpr())->getPattern(); + case Template: // FIXME: Variadic templates. - llvm_unreachable("Expression and template pack expansions unsupported"); + llvm_unreachable("Template pack expansions unsupported"); case Declaration: case Integral: @@ -343,10 +345,14 @@ TemplateArgumentLoc::getPackExpansionPattern(SourceLocation &Ellipsis, PatternTSInfo); } - case TemplateArgument::Expression: + case TemplateArgument::Expression: { + Expr *Pattern = cast<PackExpansionExpr>(Argument.getAsExpr())->getPattern(); + return TemplateArgumentLoc(Pattern, Pattern); + } + case TemplateArgument::Template: // FIXME: Variadic templates. - llvm_unreachable("Expression and template pack expansions unsupported"); + llvm_unreachable("Template pack expansions unsupported"); case TemplateArgument::Declaration: case TemplateArgument::Integral: |