[PATCH] D119814: [clang-format] Honour PointerAlignment in statements with initializers.

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 15 09:06:47 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe21db15be812: [clang-format] Honour PointerAlignment in statements with initializers. (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119814

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8417,6 +8417,13 @@
   verifyFormat(
       "/*comment*/ switch (int *p, *q; p != q) {\n  default:\n    break;\n}",
       Style);
+
+  verifyFormat("if ([](int* p, int* q) {}()) {\n}", Style);
+  verifyFormat("for ([](int* p, int* q) {}();;) {\n}", Style);
+  verifyFormat("for (; [](int* p, int* q) {}();) {\n}", Style);
+  verifyFormat("for (;; [](int* p, int* q) {}()) {\n}", Style);
+  verifyFormat("switch ([](int* p, int* q) {}()) {\n  default:\n    break;\n}",
+               Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3142,7 +3142,8 @@
     // initializers.
     if (Line.IsMultiVariableDeclStmt &&
         (Left.NestingLevel == Line.First->NestingLevel ||
-         startsWithInitStatement(Line)))
+         ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
+          startsWithInitStatement(Line))))
       return false;
     return Left.Previous && !Left.Previous->isOneOf(
                                 tok::l_paren, tok::coloncolon, tok::l_square);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119814.408905.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220215/f9a9f463/attachment.bin>


More information about the cfe-commits mailing list