[clang] 8b626a2 - [clang-format] Fix another bug in AlignConsecutiveAssignments

via cfe-commits cfe-commits at lists.llvm.org
Thu May 5 14:49:05 PDT 2022


Author: owenca
Date: 2022-05-05T14:48:56-07:00
New Revision: 8b626a2caa672a174829105ff7749d8d9a080f2a

URL: https://github.com/llvm/llvm-project/commit/8b626a2caa672a174829105ff7749d8d9a080f2a
DIFF: https://github.com/llvm/llvm-project/commit/8b626a2caa672a174829105ff7749d8d9a080f2a.diff

LOG: [clang-format] Fix another bug in AlignConsecutiveAssignments

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index cf4ef6338f1b..8563312b45bb 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -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;
         }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 78a3c21c3300..40e2cb054b24 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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


        


More information about the cfe-commits mailing list