Skip to content

Commit 2ec43f6

Browse files
committed
[clang-format] Fix a regression in ContinuationIndenter
Commit d06b923 caused a regression that breaks after a block comment adjacent to a function paramter that follows. Fixes llvm#86573.
1 parent 5964c94 commit 2ec43f6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Format/ContinuationIndenter.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
684684
// arguments to function calls. We do this by ensuring that either all
685685
// arguments (including any lambdas) go on the same line as the function
686686
// call, or we break before the first argument.
687-
auto PrevNonComment = Current.getPreviousNonComment();
687+
const auto *Prev = Current.Previous;
688+
if (!Prev)
689+
return false;
690+
// For example, `/*Newline=*/false`.
691+
if (Prev->is(TT_BlockComment) && Current.SpacesRequiredBefore == 0)
692+
return false;
693+
const auto *PrevNonComment = Current.getPreviousNonComment();
688694
if (!PrevNonComment || PrevNonComment->isNot(tok::l_paren))
689695
return false;
690696
if (Current.isOneOf(tok::comment, tok::l_paren, TT_LambdaLSquare))

clang/unittests/Format/FormatTestComments.cpp

+4
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)