[clang-format] Fix another bug in AlignConsecutiveAssignments
authorowenca <owenpiano@gmail.com>
Wed, 4 May 2022 19:25:22 +0000 (12:25 -0700)
committerowenca <owenpiano@gmail.com>
Thu, 5 May 2022 21:48:56 +0000 (14:48 -0700)
The ShouldShiftBeAdded lambda checks if extra space should be
added before the wrapped part of a braced list. If the first
element of the list is wrapped, no extra space should be added.

Fixes #55161.

Differential Revision: https://reviews.llvm.org/D124956

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

index cf4ef63..8563312 100644 (file)
@@ -398,6 +398,8 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
                 Changes[OuterScopeStart - 1].Tok->is(TT_LambdaLBrace))
               return false;
           }
+          if (Changes[ScopeStart].NewlinesBefore > 0)
+            return false;
           return true;
         }
 
index 78a3c21..40e2cb0 100644 (file)
@@ -18023,6 +18023,12 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
                "}",
                Style);
 
+  verifyFormat("unsigned i = 0;\n"
+               "int a[]    = {\n"
+               "    1234567890,\n"
+               "    -1234567890};",
+               Style);
+
   Style.ColumnLimit = 120;
 
   // clang-format off