Skip to content

Commit 8fc8a84

Browse files
authored
[clang-format] Allow breaking before kw___attribute (#128623)
Fixes #74784
1 parent c53eb93 commit 8fc8a84

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6202,6 +6202,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62026202
TT_ClassHeadName, tok::kw_operator)) {
62036203
return true;
62046204
}
6205+
if (Right.isAttribute())
6206+
return true;
62056207
if (Left.is(TT_PointerOrReference))
62066208
return false;
62076209
if (Right.isTrailingComment()) {
@@ -6346,9 +6348,6 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
63466348
tok::less, tok::coloncolon);
63476349
}
63486350

6349-
if (Right.isAttribute())
6350-
return true;
6351-
63526351
if (Right.is(tok::l_square) && Right.is(TT_AttributeSquare))
63536352
return Left.isNot(TT_AttributeSquare);
63546353

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12613,6 +12613,9 @@ TEST_F(FormatTest, UnderstandsAttributes) {
1261312613
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n"
1261412614
"aaaaaaaaaaaaaaaaaaaaaaa(int i);");
1261512615
verifyFormat("__attribute__((nodebug)) ::qualified_type f();");
12616+
verifyFormat(
12617+
"RenderWidgetHostViewCocoa *\n"
12618+
" __attribute__((objc_precise_lifetime)) keepSelfAlive = self;");
1261612619
FormatStyle AfterType = getLLVMStyle();
1261712620
AfterType.BreakAfterReturnType = FormatStyle::RTBS_All;
1261812621
verifyFormat("__attribute__((nodebug)) void\n"

0 commit comments

Comments
 (0)