[llvm-branch-commits] [clang] release/20.x: [clang-format] Fix the indent of StartOfName after Attr… (PR #141004)
Owen Pan via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed May 21 21:41:12 PDT 2025
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/141004
…ibuteMacro (#140361)
Backport 0cac25bcf5a246eb8a1f02d5041731ae9a6f00e0
>From b05983ec62a831de375e96f9ddb9e87e8043049d Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Wed, 21 May 2025 21:37:54 -0700
Subject: [PATCH] release/20.x: [clang-format] Fix the indent of StartOfName
after AttributeMacro (#140361)
Backport 0cac25bcf5a246eb8a1f02d5041731ae9a6f00e0
---
clang/lib/Format/ContinuationIndenter.cpp | 4 +++-
clang/unittests/Format/FormatTest.cpp | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 6f7d213c0b559..d953348b0258d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1452,7 +1452,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 90a79230e9f4c..1afcc75a2e19e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12419,6 +12419,13 @@ TEST_F(FormatTest, UnderstandsAttributes) {
verifyFormat("SomeType s __unused{InitValue};", CustomAttrs);
verifyFormat("SomeType *__capability s(InitValue);", CustomAttrs);
verifyFormat("SomeType *__capability s{InitValue};", CustomAttrs);
+
+ 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 llvm-branch-commits
mailing list