From 342e1c77c360e745fc6457037e6c1e37b84f2791 Mon Sep 17 00:00:00 2001 From: owenca Date: Tue, 3 May 2022 12:04:50 -0700 Subject: [PATCH] [clang-format] Fix a bug in AlignConsecutiveAssignments Fixes #55113. Differential Revision: https://reviews.llvm.org/D124868 --- clang/lib/Format/WhitespaceManager.cpp | 2 ++ clang/unittests/Format/FormatTest.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 2dcc4fd..cf4ef63 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -369,6 +369,8 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, if (Changes[i].Tok->MatchingParen && Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace)) return false; + if (Changes[ScopeStart].NewlinesBefore > 0) + return false; return Style.BinPackArguments; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 37f3269..78a3c21 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -18010,11 +18010,21 @@ TEST_F(FormatTest, AlignWithLineBreaks) { 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(monitorFrequencyUsec),\n" -- 2.7.4