[clang] [clang-format] Fix the indent of StartOfName after AttributeMacro (PR #140361)
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 17 00:29:17 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
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
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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/140361
More information about the cfe-commits
mailing list