Skip to content

Commit b05983e

Browse files
committed
release/20.x: [clang-format] Fix the indent of StartOfName after AttributeMacro (llvm#140361)
Backport 0cac25b
1 parent 5befd1f commit b05983e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
14521452
(PreviousNonComment->ClosesTemplateDeclaration ||
14531453
PreviousNonComment->ClosesRequiresClause ||
14541454
(PreviousNonComment->is(TT_AttributeMacro) &&
1455-
Current.isNot(tok::l_paren)) ||
1455+
Current.isNot(tok::l_paren) &&
1456+
!Current.endsSequence(TT_StartOfName, TT_AttributeMacro,
1457+
TT_PointerOrReference)) ||
14561458
PreviousNonComment->isOneOf(
14571459
TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
14581460
TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12419,6 +12419,13 @@ TEST_F(FormatTest, UnderstandsAttributes) {
1241912419
verifyFormat("SomeType s __unused{InitValue};", CustomAttrs);
1242012420
verifyFormat("SomeType *__capability s(InitValue);", CustomAttrs);
1242112421
verifyFormat("SomeType *__capability s{InitValue};", CustomAttrs);
12422+
12423+
auto Style = getLLVMStyleWithColumns(60);
12424+
Style.AttributeMacros.push_back("my_fancy_attr");
12425+
Style.PointerAlignment = FormatStyle::PAS_Left;
12426+
verifyFormat("void foo(const MyLongTypeNameeeeeeeeeeeee* my_fancy_attr\n"
12427+
" testttttttttt);",
12428+
Style);
1242212429
}
1242312430

1242412431
TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) {

0 commit comments

Comments
 (0)