This revision was automatically updated to reflect the committed changes. Closed by commit rGa130cf8ae8ab: [clang] Fix printing of lambdas with capture expressions (authored by walrus, committed by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83855/new/ https://reviews.llvm.org/D83855 Files: clang/lib/AST/StmtPrinter.cpp clang/test/AST/ast-printer-lambda.cpp Index: clang/test/AST/ast-printer-lambda.cpp =================================================================== --- clang/test/AST/ast-printer-lambda.cpp +++ clang/test/AST/ast-printer-lambda.cpp @@ -15,6 +15,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 +43,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 Index: clang/lib/AST/StmtPrinter.cpp =================================================================== --- clang/lib/AST/StmtPrinter.cpp +++ 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 && + !isa<ParenListExpr>(D->getInit())) { + Pre = "("; + Post = ")"; + } else if (D->getInitStyle() == VarDecl::CInit) { + Pre = " = "; + } + + OS << Pre; + PrintExpr(D->getInit()); + OS << Post; + } } OS << ']';
Index: clang/test/AST/ast-printer-lambda.cpp =================================================================== --- clang/test/AST/ast-printer-lambda.cpp +++ clang/test/AST/ast-printer-lambda.cpp @@ -15,6 +15,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 +43,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 Index: clang/lib/AST/StmtPrinter.cpp =================================================================== --- clang/lib/AST/StmtPrinter.cpp +++ 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 && + !isa<ParenListExpr>(D->getInit())) { + Pre = "("; + Post = ")"; + } else if (D->getInitStyle() == VarDecl::CInit) { + Pre = " = "; + } + + OS << Pre; + PrintExpr(D->getInit()); + OS << Post; + } } OS << ']';
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits