diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -2005,8 +2005,23 @@ if (C->isPackExpansion()) OS << "..."; - if (Node->isInitCapture(C)) - PrintExpr(C->getCapturedVar()->getInit()); + if (Node->isInitCapture(C)) { + VarDecl *D = C->getCapturedVar(); + + llvm::StringRef Pre; + llvm::StringRef Post; + if (D->getInitStyle() == VarDecl::CallInit) { + if (!isa(D->getInit())) { + Pre = "("; + Post = ")"; + } + } else if (D->getInitStyle() == VarDecl::CInit) + Pre = " = "; + + OS << Pre; + PrintExpr(D->getInit()); + OS << Post; + } } OS << ']'; diff --git a/clang/test/AST/ast-printer-lambda.cpp b/clang/test/AST/ast-printer-lambda.cpp --- a/clang/test/AST/ast-printer-lambda.cpp +++ b/clang/test/AST/ast-printer-lambda.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -ast-print -std=c++17 %s | FileCheck %s +struct M {}; + struct S { template void test1(int i, T... t) { @@ -15,6 +17,18 @@ auto lambda = [&]{}; //CHECK: [&] { } +{ + auto lambda = [k{i}] {}; + //CHECK: [k{i}] { +} +{ + auto lambda = [k(i)] {}; + //CHECK: [k(i)] { +} +{ + auto lambda = [k = i] {}; + //CHECK: [k = i] { +} { auto lambda = [t..., i]{}; //CHECK: [t..., i] { @@ -31,6 +45,14 @@ auto lambda = [t..., this]{}; //CHECK: [t..., this] { } +{ + auto lambda = [k(t...)] {}; + //CHECK: [k(t...)] { +} +{ + auto lambda = [k{t...}] {}; + //CHECK: [k{t...}] { +} } }; \ No newline at end of file