Skip to content

Commit 6dbaa89

Browse files
owencallvmbot
authored andcommitted
[clang-format] Fix a regression in ContinuationIndenter (llvm#88414)
Commit d06b923 caused a regression that breaks after a block comment adjacent to a function paramter that follows. Fixes llvm#86573. (cherry picked from commit d61edec)
1 parent 51ff7f3 commit 6dbaa89

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
674674
// arguments to function calls. We do this by ensuring that either all
675675
// arguments (including any lambdas) go on the same line as the function
676676
// call, or we break before the first argument.
677-
auto PrevNonComment = Current.getPreviousNonComment();
677+
const auto *Prev = Current.Previous;
678+
if (!Prev)
679+
return false;
680+
// For example, `/*Newline=*/false`.
681+
if (Prev->is(TT_BlockComment) && Current.SpacesRequiredBefore == 0)
682+
return false;
683+
const auto *PrevNonComment = Current.getPreviousNonComment();
678684
if (!PrevNonComment || PrevNonComment->isNot(tok::l_paren))
679685
return false;
680686
if (Current.isOneOf(tok::comment, tok::l_paren, TT_LambdaLSquare))

clang/unittests/Format/FormatTestComments.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ TEST_F(FormatTestComments, RemovesTrailingWhitespaceOfComments) {
376376
TEST_F(FormatTestComments, UnderstandsBlockComments) {
377377
verifyFormat("f(/*noSpaceAfterParameterNamingComment=*/true);");
378378
verifyFormat("void f() { g(/*aaa=*/x, /*bbb=*/!y, /*c=*/::c); }");
379+
verifyFormat("fooooooooooooooooooooooooooooo(\n"
380+
" /*qq_=*/move(q), [this, b](bar<void(uint32_t)> b) {},\n"
381+
" c);",
382+
getLLVMStyleWithColumns(60));
379383
EXPECT_EQ("f(aaaaaaaaaaaaaaaaaaaaaaaaa, /* Trailing comment for aa... */\n"
380384
" bbbbbbbbbbbbbbbbbbbbbbbbb);",
381385
format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \\\n"

0 commit comments

Comments
 (0)