Skip to content

Commit ffd90ed

Browse files
krasimirggtstellar
authored andcommitted
[clang-format] handle trailing comments in function definition detection
A follow-up to f6bc614 where we handle the case where the semicolon is followed by a trailing comment. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D107907 (cherry picked from commit 0fc27ef)
1 parent b685e13 commit ffd90ed

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
24822482
// return i + 1;
24832483
// }
24842484
if (Next->Next && Next->Next->is(tok::identifier) &&
2485-
Line.Last->isNot(tok::semi))
2485+
!Line.endsWith(tok::semi))
24862486
return true;
24872487
for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
24882488
Tok = Tok->Next) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8244,6 +8244,9 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
82448244
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
82458245
" ABSL_GUARDED_BY(mutex) = {};",
82468246
getGoogleStyleWithColumns(40));
8247+
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
8248+
" ABSL_GUARDED_BY(mutex); // comment",
8249+
getGoogleStyleWithColumns(40));
82478250

82488251
Style = getGNUStyle();
82498252

0 commit comments

Comments
 (0)