[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:20 PST 2024


================
@@ -4344,6 +4344,112 @@ class SizeOfPackExpr final
   }
 };
 
+class PackIndexingExpr final
+    : public Expr,
+      private llvm::TrailingObjects<PackIndexingExpr, Expr *> {
+  friend class ASTStmtReader;
+  friend class ASTStmtWriter;
+  friend TrailingObjects;
+
+  SourceLocation EllipsisLoc;
+
+  // The location of the closing bracket
+  SourceLocation RSquareLoc;
+
+  // The pack being indexed, followed by the index
+  Stmt *SubExprs[2];
+
+  // The evaluated index
+  std::optional<int64_t> Index;
+
+  size_t TransformedExpressions;
+
+  PackIndexingExpr(QualType Type, SourceLocation EllipsisLoc,
+                   SourceLocation RSquareLoc, Expr *PackIdExpr, Expr *IndexExpr,
+                   std::optional<int64_t> Index = std::nullopt,
+                   ArrayRef<Expr *> SubstitutedExprs = {})
+      : Expr(PackIndexingExprClass, Type, VK_LValue, OK_Ordinary),
+        EllipsisLoc(EllipsisLoc), RSquareLoc(RSquareLoc),
+        SubExprs{PackIdExpr, IndexExpr}, Index(Index),
+        TransformedExpressions(SubstitutedExprs.size()) {
+
+    auto *Exprs = getTrailingObjects<Expr *>();
+    std::uninitialized_copy(SubstitutedExprs.begin(), SubstitutedExprs.end(),
+                            Exprs);
+
+    ExprDependence D = IndexExpr->getDependence();
----------------
erichkeane wrote:

I THINK most of this dependence calculation should be moved into the 'calculateDependence' infrastructure, right?  There is a file somewhere where all of these are implemented.

https://github.com/llvm/llvm-project/pull/72644


More information about the cfe-commits mailing list