Skip to content

Commit ca69a8d

Browse files
[clang-format] Fix ColumnLimit violation while aligning (#165627)
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 0c707c9 commit ca69a8d

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
@@ -20824,6 +20824,13 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
2082420824
" argument1,\n"
2082520825
" argument2);",
2082620826
Style);
20827+
20828+
Style.ColumnLimit = 45;
20829+
verifyFormat("auto xxxxxxxx = foo;\n"
20830+
"auto x = whatever ? some / long -\n"
20831+
" computition / stuff\n"
20832+
" : random;",
20833+
Style);
2082720834
}
2082820835

2082920836
TEST_F(FormatTest, AlignWithInitializerPeriods) {

0 commit comments

Comments
 (0)