[PATCH] D124868: [clang-format] Fix a bug in AlignConsecutiveAssignments

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 4 12:05:01 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG342e1c77c360: [clang-format] Fix a bug in AlignConsecutiveAssignments (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124868

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18010,11 +18010,21 @@
                Style);
   // clang-format on
 
-  Style = getLLVMStyleWithColumns(120);
+  Style = getLLVMStyleWithColumns(20);
   Style.AlignConsecutiveAssignments.Enabled = true;
-  Style.ContinuationIndentWidth = 4;
   Style.IndentWidth = 4;
 
+  verifyFormat("void foo() {\n"
+               "    int i1 = 1;\n"
+               "    int j  = 0;\n"
+               "    int k  = bar(\n"
+               "        argument1,\n"
+               "        argument2);\n"
+               "}",
+               Style);
+
+  Style.ColumnLimit = 120;
+
   // clang-format off
   verifyFormat("void SomeFunc() {\n"
                "    newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -369,6 +369,8 @@
           if (Changes[i].Tok->MatchingParen &&
               Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace))
             return false;
+          if (Changes[ScopeStart].NewlinesBefore > 0)
+            return false;
           return Style.BinPackArguments;
         }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124868.427104.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220504/f7bd5a7d/attachment.bin>


More information about the cfe-commits mailing list