[clang] 0cac25b - [clang-format] Fix the indent of StartOfName after AttributeMacro (#140361)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 19 01:29:19 PDT 2025


Author: Owen Pan
Date: 2025-05-19T01:29:16-07:00
New Revision: 0cac25bcf5a246eb8a1f02d5041731ae9a6f00e0

URL: https://github.com/llvm/llvm-project/commit/0cac25bcf5a246eb8a1f02d5041731ae9a6f00e0
DIFF: https://github.com/llvm/llvm-project/commit/0cac25bcf5a246eb8a1f02d5041731ae9a6f00e0.diff

LOG: [clang-format] Fix the indent of StartOfName after AttributeMacro (#140361)

Fix #139510

Added: 
    

Modified: 
    clang/lib/Format/ContinuationIndenter.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 55e1d1ceb55b7..4e4e48f90a89f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1475,7 +1475,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
        (PreviousNonComment->ClosesTemplateDeclaration ||
         PreviousNonComment->ClosesRequiresClause ||
         (PreviousNonComment->is(TT_AttributeMacro) &&
-         Current.isNot(tok::l_paren)) ||
+         Current.isNot(tok::l_paren) &&
+         !Current.endsSequence(TT_StartOfName, TT_AttributeMacro,
+                               TT_PointerOrReference)) ||
         PreviousNonComment->isOneOf(
             TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
             TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||

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) {


        


More information about the cfe-commits mailing list