]> granicus.if.org Git - clang/commitdiff
[clang] Respect TerseOutput when printing lambdas
authorKadir Cetinkaya <kadircet@google.com>
Mon, 27 May 2019 16:20:45 +0000 (16:20 +0000)
committerKadir Cetinkaya <kadircet@google.com>
Mon, 27 May 2019 16:20:45 +0000 (16:20 +0000)
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
unittests/AST/StmtPrinterTest.cpp

index ea0b472d98b8b29a9875627a1883f9db175667b8..b06edb4b6db157511c0a31a32bb42863c29a4060 100644 (file)
@@ -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) {
index 0d383d547a2ecd558306fb07f6e17516acb14d8d..080c18b0737b25e09d30a03369cab1c46f8e3ea0 100644 (file)
@@ -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; })));
+}