Skip to content

Commit 0fc27ef

Browse files
committed
[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
1 parent 645f589 commit 0fc27ef

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
@@ -8252,6 +8252,9 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
82528252
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
82538253
" ABSL_GUARDED_BY(mutex) = {};",
82548254
getGoogleStyleWithColumns(40));
8255+
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
8256+
" ABSL_GUARDED_BY(mutex); // comment",
8257+
getGoogleStyleWithColumns(40));
82558258

82568259
Style = getGNUStyle();
82578260

0 commit comments

Comments
 (0)