From 3098b618c7d10cd82cfe977b53a76df8b822266b Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya <kadircet@google.com> Date: Mon, 27 May 2019 16:20:45 +0000 Subject: [PATCH] [clang] Respect TerseOutput when printing lambdas Reviewers: ilya-biryukov, hokein, sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62487 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361771 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/StmtPrinter.cpp | 5 ++++- unittests/AST/StmtPrinterTest.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index ea0b472d98..b06edb4b6d 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1950,7 +1950,10 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { // Print the body. OS << ' '; - PrintRawCompoundStmt(Node->getBody()); + if (Policy.TerseOutput) + OS << "{}"; + else + PrintRawCompoundStmt(Node->getBody()); } void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) { diff --git a/unittests/AST/StmtPrinterTest.cpp b/unittests/AST/StmtPrinterTest.cpp index 0d383d547a..080c18b073 100644 --- a/unittests/AST/StmtPrinterTest.cpp +++ b/unittests/AST/StmtPrinterTest.cpp @@ -231,3 +231,17 @@ class A { ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"), "return self->ivar;\n")); } + +TEST(StmtPrinter, TerseOutputWithLambdas) { + const char *CPPSource = "auto lamb = []{ return 0; };"; + + // body is printed when TerseOutput is off(default). + ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11, CPPSource, + lambdaExpr(anything()).bind("id"), + "[] {\n return 0;\n}")); + + // body not printed when TerseOutput is on. + ASSERT_TRUE(PrintedStmtCXXMatches( + StdVer::CXX11, CPPSource, lambdaExpr(anything()).bind("id"), "[] {}", + PolicyAdjusterType([](PrintingPolicy &PP) { PP.TerseOutput = true; }))); +} -- 2.40.0