[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 05:32:28 PST 2024


================
@@ -1061,6 +1070,59 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
                                 RParenLoc);
 }
 
+static bool isParameterPack(Expr *PackExpression) {
+  if (auto D = dyn_cast<DeclRefExpr>(PackExpression); D) {
+    ValueDecl *VD = D->getDecl();
+    return VD->isParameterPack();
+  }
+  return false;
+}
+
+ExprResult Sema::ActOnPackIndexingExpr(Scope *S, Expr *PackExpression,
+                                       SourceLocation EllipsisLoc,
+                                       SourceLocation LSquareLoc,
+                                       Expr *IndexExpr,
+                                       SourceLocation RSquareLoc) {
+  bool isParameterPack = ::isParameterPack(PackExpression);
+  if (!isParameterPack) {
+    CorrectDelayedTyposInExpr(IndexExpr);
+    Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
+        << PackExpression;
+    return ExprError();
+  }
+  return BuildPackIndexingExpr(PackExpression, EllipsisLoc, IndexExpr,
+                               RSquareLoc);
+}
+
+ExprResult
+Sema::BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc,
+                            Expr *IndexExpr, SourceLocation RSquareLoc,
+                            ArrayRef<Expr *> ExpandedExprs, bool EmptyPack) {
+
+  std::optional<int64_t> Index;
+  if (!IndexExpr->isValueDependent() && !IndexExpr->isTypeDependent()) {
+    llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
+    // TODO: do we need a new enumerator instead of CCEK_ArrayBound?
----------------
cor3ntin wrote:

It can't be a vla

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


More information about the cfe-commits mailing list