[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 9 10:21:22 PST 2024
================
@@ -1665,6 +1665,43 @@ NonTypeTemplateParmDecl *SubstNonTypeTemplateParmExpr::getParameter() const {
getReplacedTemplateParameterList(getAssociatedDecl())->asArray()[Index]);
}
+PackIndexingExpr *PackIndexingExpr::Create(ASTContext &Context,
+ SourceLocation EllipsisLoc,
+ SourceLocation RSquareLoc,
+ Expr *PackIdExpr, Expr *IndexExpr,
+ std::optional<int64_t> Index,
+ ArrayRef<Expr *> SubstitutedExprs) {
+ QualType Type;
+ if (Index && !SubstitutedExprs.empty())
+ Type = SubstitutedExprs[*Index]->getType();
+ else
+ Type = Context.DependentTy;
+
+ void *Storage =
+ Context.Allocate(totalSizeToAlloc<Expr *>(SubstitutedExprs.size()));
+ return new (Storage)
+ PackIndexingExpr(Type, EllipsisLoc, RSquareLoc, PackIdExpr, IndexExpr,
+ Index, SubstitutedExprs);
+}
+
+NamedDecl *PackIndexingExpr::getPackDecl() const {
+ if (auto *D = dyn_cast<DeclRefExpr>(getPackIdExpression()); D) {
+ NamedDecl *ND = dyn_cast<NamedDecl>(D->getDecl());
+ assert(ND && "exected a named decl");
+ return ND;
+ }
+ assert(false && "Non variables packs not supported");
----------------
erichkeane wrote:
Is this 'not supported' or 'not valid'?
https://github.com/llvm/llvm-project/pull/72644
More information about the cfe-commits
mailing list