Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] Fix a regression in ContinuationIndenter #88414

Merged
merged 1 commit into from
Apr 12, 2024
Merged

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Apr 11, 2024

Commit d06b923 caused a regression that breaks after a block comment adjacent to a function paramter that follows.

Fixes #86573.

Commit d06b923 caused a regression that breaks after a block comment
adjacent to a function paramter that follows.

Fixes llvm#86573.
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 11, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Commit d06b923 caused a regression that breaks after a block comment adjacent to a function paramter that follows.

Fixes #86573.


Full diff: https://github.com/llvm/llvm-project/pull/88414.diff

2 Files Affected:

  • (modified) clang/lib/Format/ContinuationIndenter.cpp (+7-1)
  • (modified) clang/unittests/Format/FormatTestComments.cpp (+4)
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"

@owenca owenca added this to the LLVM 18.X Release milestone Apr 11, 2024
@owenca owenca merged commit d61edec into llvm:main Apr 12, 2024
7 checks passed
@owenca owenca deleted the 86573 branch April 12, 2024 17:12
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
Commit d06b923 caused a regression that breaks after a block
comment adjacent to a function paramter that follows.

Fixes llvm#86573.
@owenca
Copy link
Contributor Author

owenca commented Apr 19, 2024

/cherry-pick d61edec

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Apr 19, 2024
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)
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 19, 2024

/pull-request #89412

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Apr 26, 2024
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)
@pointhex pointhex mentioned this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[clang-format] odd line break with c-style comment in argument list
3 participants