[clang] [Clang][AST] Fix PackIndexingExpr AST printout (PR #117947)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 17:22:21 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (AlexErofeev)

<details>
<summary>Changes</summary>

Fixes #<!-- -->116486 
Also added regression unit test

---
Full diff: https://github.com/llvm/llvm-project/pull/117947.diff


2 Files Affected:

- (modified) clang/lib/AST/StmtPrinter.cpp (+4-1) 
- (added) clang/test/AST/ast-print-packindexingexpr.cpp (+9) 


``````````diff
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index c8677d11b64e8d..7507c9d14327a0 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2514,7 +2514,10 @@ void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
 }
 
 void StmtPrinter::VisitPackIndexingExpr(PackIndexingExpr *E) {
-  OS << E->getPackIdExpression() << "...[" << E->getIndexExpr() << "]";
+  PrintExpr(E->getPackIdExpression());
+  OS << "...[";
+  PrintExpr(E->getIndexExpr());
+  OS << "]";
 }
 
 void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
diff --git a/clang/test/AST/ast-print-packindexingexpr.cpp b/clang/test/AST/ast-print-packindexingexpr.cpp
new file mode 100644
index 00000000000000..157abeb99436a2
--- /dev/null
+++ b/clang/test/AST/ast-print-packindexingexpr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -ast-print -std=c++2c %s | FileCheck %s
+
+template <class... T, unsigned N>
+auto foo(T ...params) {
+  return params...[N];
+}
+
+// CHECK: template <class ...T, unsigned int N> auto foo(T ...params) {
+// CHECK-NEXT: return params...[N];

``````````

</details>


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


More information about the cfe-commits mailing list