Skip to content

[clang-format] Fix the indent of StartOfName after AttributeMacro #140361

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

Merged
merged 1 commit into from
May 19, 2025

Conversation

owenca
Copy link
Contributor

@owenca owenca commented May 17, 2025

Fix #139510

@llvmbot
Copy link
Member

llvmbot commented May 17, 2025

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Fix #139510


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

2 Files Affected:

  • (modified) clang/lib/Format/ContinuationIndenter.cpp (+2)
  • (modified) clang/unittests/Format/FormatTest.cpp (+7)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 55e1d1ceb55b7..b31fb29e7c4a0 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1475,6 +1475,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
        (PreviousNonComment->ClosesTemplateDeclaration ||
         PreviousNonComment->ClosesRequiresClause ||
         (PreviousNonComment->is(TT_AttributeMacro) &&
+         !Current.endsSequence(TT_StartOfName, TT_AttributeMacro,
+                               TT_PointerOrReference) &&
          Current.isNot(tok::l_paren)) ||
         PreviousNonComment->isOneOf(
             TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 436beaf68bd2a..8fe57c80cbe25 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12714,6 +12714,13 @@ TEST_F(FormatTest, UnderstandsAttributes) {
   verifyGoogleFormat("SomeType* absl_nullable s{InitValue};");
   verifyGoogleFormat("SomeType* absl_nullability_unknown s(InitValue);");
   verifyGoogleFormat("SomeType* absl_nullability_unknown s{InitValue};");
+
+  auto Style = getLLVMStyleWithColumns(60);
+  Style.AttributeMacros.push_back("my_fancy_attr");
+  Style.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("void foo(const MyLongTypeNameeeeeeeeeeeee* my_fancy_attr\n"
+               "             testttttttttt);",
+               Style);
 }
 
 TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) {

@owenca owenca merged commit 0cac25b into llvm:main May 19, 2025
11 checks passed
@owenca owenca deleted the 139510 branch May 19, 2025 08:29
@llvm llvm deleted a comment from llvm-ci May 19, 2025
@owenca owenca added this to the LLVM 20.X Release milestone May 22, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status May 22, 2025
@owenca
Copy link
Contributor Author

owenca commented May 22, 2025

/cherry-pick 0cac25b

@llvmbot
Copy link
Member

llvmbot commented May 22, 2025

Failed to cherry-pick: 0cac25b

https://github.com/llvm/llvm-project/actions/runs/15177822654

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

Wrong indentation around attribute macros with PointerAlignment: Left
3 participants