Skip to content

Commit 5125a02

Browse files
committedMay 5, 2019
[clang] fixing -ast-print for variadic parameter pack in lambda capture
Summary: currently for: ``` template<typename ... T> void f(T... t) { auto l = [t...]{}; } ``` `clang -ast-print file.cpp` outputs: ``` template <typename ...T> void f(T ...t) { auto l = [t] { } ; } ``` notice that there is not `...` in the capture list of the lambda. this patch fixes this issue. and add test for it. Patch by Tyker Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61556 llvm-svn: 359980
1 parent ee05717 commit 5125a02

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
 

‎clang/lib/AST/StmtPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,9 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
18951895
llvm_unreachable("VLA type in explicit captures.");
18961896
}
18971897

1898+
if (C->isPackExpansion())
1899+
OS << "...";
1900+
18981901
if (Node->isInitCapture(C))
18991902
PrintExpr(C->getCapturedVar()->getInit());
19001903
}

‎clang/test/AST/ast-printer-lambda.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 -ast-print -std=c++17 %s | FileCheck %s
2+
3+
struct S {
4+
template<typename ... T>
5+
void test1(int i, T... t) {
6+
{
7+
auto lambda = [i]{};
8+
//CHECK: [i] {
9+
}
10+
{
11+
auto lambda = [=]{};
12+
//CHECK: [=] {
13+
}
14+
{
15+
auto lambda = [&]{};
16+
//CHECK: [&] {
17+
}
18+
{
19+
auto lambda = [t..., i]{};
20+
//CHECK: [t..., i] {
21+
}
22+
{
23+
auto lambda = [&t...]{};
24+
//CHECK: [&t...] {
25+
}
26+
{
27+
auto lambda = [this, &t...]{};
28+
//CHECK: [this, &t...] {
29+
}
30+
{
31+
auto lambda = [t..., this]{};
32+
//CHECK: [t..., this] {
33+
}
34+
}
35+
36+
};

0 commit comments

Comments
 (0)
Please sign in to comment.