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,17 @@ if (C->isPackExpansion()) OS << "..."; - if (Node->isInitCapture(C)) - PrintExpr(C->getCapturedVar()->getInit()); + if (Node->isInitCapture(C)) { + VarDecl *D = C->getCapturedVar(); + Expr *Init = D->getInit(); + if (D->getInitStyle() == VarDecl::CallInit && !isa(Init)) + OS << "("; + else if (D->getInitStyle() == VarDecl::CInit) + OS << " = "; + PrintExpr(Init); + if (D->getInitStyle() == VarDecl::CallInit && !isa(Init)) + OS << ")"; + } } 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 @@ -15,6 +15,22 @@ 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 = [&k = i] {}; + //CHECK: [&k = i] { +} { auto lambda = [t..., i]{}; //CHECK: [t..., i] {