[clang] [Clang][Sema] Avoid pack expansion for expanded empty PackIndexingExprs (PR #92385)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Mon May 20 08:11:46 PDT 2024


================
@@ -2157,11 +2157,11 @@ void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
 void ASTStmtWriter::VisitPackIndexingExpr(PackIndexingExpr *E) {
   VisitExpr(E);
   Record.push_back(E->TransformedExpressions);
+  Record.push_back(E->EmptyPack);
   Record.AddSourceLocation(E->getEllipsisLoc());
   Record.AddSourceLocation(E->getRSquareLoc());
   Record.AddStmt(E->getPackIdExpression());
   Record.AddStmt(E->getIndexExpr());
-  Record.push_back(E->TransformedExpressions);
----------------
zyn0217 wrote:

> Weird that this did not cause any issues...

I think that's just because we didn't test it (nor does anyone... use it at scale). Anyhow, I contrived an example that would previously crash in `clang/test/PCH/pack_indexing.cpp`:
```cpp
template <int I, auto...V>
decltype(V...[I]) foo() { return V...[I]; }

void fn1() {
  foo<1, 2, 3, 4>();
}
```

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


More information about the cfe-commits mailing list