[clang] [clang-format] Fix a regression in ContinuationIndenter (PR #88414)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 11 10:01:43 PDT 2024
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/88414
Commit d06b92391513 caused a regression that breaks after a block comment adjacent to a function paramter that follows.
Fixes #86573.
>From 2ec43f6dc1fafed9d7fc324eeacfa07133af3abd Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Thu, 11 Apr 2024 09:40:01 -0700
Subject: [PATCH] [clang-format] Fix a regression in ContinuationIndenter
Commit d06b92391513 caused a regression that breaks after a block comment
adjacent to a function paramter that follows.
Fixes #86573.
---
clang/lib/Format/ContinuationIndenter.cpp | 8 +++++++-
clang/unittests/Format/FormatTestComments.cpp | 4 ++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 700bce35c86839..ad0e2c3c620c32 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -684,7 +684,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// arguments to function calls. We do this by ensuring that either all
// arguments (including any lambdas) go on the same line as the function
// call, or we break before the first argument.
- auto PrevNonComment = Current.getPreviousNonComment();
+ const auto *Prev = Current.Previous;
+ if (!Prev)
+ return false;
+ // For example, `/*Newline=*/false`.
+ if (Prev->is(TT_BlockComment) && Current.SpacesRequiredBefore == 0)
+ return false;
+ const auto *PrevNonComment = Current.getPreviousNonComment();
if (!PrevNonComment || PrevNonComment->isNot(tok::l_paren))
return false;
if (Current.isOneOf(tok::comment, tok::l_paren, TT_LambdaLSquare))
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index d705cf34d8af02..d2baace6a7d809 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -376,6 +376,10 @@ TEST_F(FormatTestComments, RemovesTrailingWhitespaceOfComments) {
TEST_F(FormatTestComments, UnderstandsBlockComments) {
verifyFormat("f(/*noSpaceAfterParameterNamingComment=*/true);");
verifyFormat("void f() { g(/*aaa=*/x, /*bbb=*/!y, /*c=*/::c); }");
+ verifyFormat("fooooooooooooooooooooooooooooo(\n"
+ " /*qq_=*/move(q), [this, b](bar<void(uint32_t)> b) {},\n"
+ " c);",
+ getLLVMStyleWithColumns(60));
EXPECT_EQ("f(aaaaaaaaaaaaaaaaaaaaaaaaa, /* Trailing comment for aa... */\n"
" bbbbbbbbbbbbbbbbbbbbbbbbb);",
format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \\\n"
More information about the cfe-commits
mailing list