Skip to content

Commit c03e974

Browse files
[clang-format] Fix ColumnLimit violation while aligning
It did compute the length only on the first line, and thus the following lines could be (and in the test example were) moved over the column limit, when the = was aligned.
1 parent 4cb73cd commit c03e974

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
591591
CurrentChangeWidthRight = CurrentChange.TokenLength;
592592
const FormatToken *MatchingParenToEncounter = nullptr;
593593
for (unsigned J = I + 1;
594-
J != E && (Changes[J].NewlinesBefore == 0 || MatchingParenToEncounter);
594+
J != E && (Changes[J].NewlinesBefore == 0 ||
595+
MatchingParenToEncounter || Changes[J].IsAligned);
595596
++J) {
596597
const auto &Change = Changes[J];
597598
const auto *Tok = Change.Tok;

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20820,6 +20820,13 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
2082020820
" argument1,\n"
2082120821
" argument2);",
2082220822
Style);
20823+
20824+
Style.ColumnLimit = 45;
20825+
verifyFormat("auto xxxxxxxx = foo;\n"
20826+
"auto x = whatever ? some / long -\n"
20827+
" computition / stuff\n"
20828+
" : random;",
20829+
Style);
2082320830
}
2082420831

2082520832
TEST_F(FormatTest, AlignWithInitializerPeriods) {

0 commit comments

Comments
 (0)