[PATCH] D62487: [clang] Respect TerseOutput when printing lambdas

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 09:18:06 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL361771: [clang] Respect TerseOutput when printing lambdas (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62487?vs=201534&id=201540#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62487/new/

https://reviews.llvm.org/D62487

Files:
  cfe/trunk/lib/AST/StmtPrinter.cpp
  cfe/trunk/unittests/AST/StmtPrinterTest.cpp


Index: cfe/trunk/unittests/AST/StmtPrinterTest.cpp
===================================================================
--- cfe/trunk/unittests/AST/StmtPrinterTest.cpp
+++ cfe/trunk/unittests/AST/StmtPrinterTest.cpp
@@ -231,3 +231,17 @@
   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; })));
+}
Index: cfe/trunk/lib/AST/StmtPrinter.cpp
===================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp
+++ cfe/trunk/lib/AST/StmtPrinter.cpp
@@ -1950,7 +1950,10 @@
 
   // Print the body.
   OS << ' ';
-  PrintRawCompoundStmt(Node->getBody());
+  if (Policy.TerseOutput)
+    OS << "{}";
+  else
+    PrintRawCompoundStmt(Node->getBody());
 }
 
 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62487.201540.patch
Type: text/x-patch
Size: 1457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190527/894f2335/attachment.bin>


More information about the cfe-commits mailing list