[PATCH] D107907: [clang-format] handle trailing comments in function definition detection
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 11 08:06:56 PDT 2021
krasimir created this revision.
krasimir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
A follow-up to
https://github.com/llvm/llvm-project/commit/f6bc614546e169bb1b17a29c422ebace038e6c62
where we handle the case where the semicolon is followed by a trailing
comment.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107907
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8252,6 +8252,9 @@
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
" ABSL_GUARDED_BY(mutex) = {};",
getGoogleStyleWithColumns(40));
+ verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
+ " ABSL_GUARDED_BY(mutex); // comment",
+ getGoogleStyleWithColumns(40));
Style = getGNUStyle();
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2481,9 +2481,13 @@
// {
// return i + 1;
// }
- if (Next->Next && Next->Next->is(tok::identifier) &&
- Line.Last->isNot(tok::semi))
- return true;
+ if (Next->Next && Next->Next->is(tok::identifier)) {
+ const FormatToken *Last = Line.Last;
+ if (Last && Last->is(tok::comment))
+ Last = Last->getPreviousNonComment();
+ if (Last && Last->isNot(tok::semi))
+ return true;
+ }
for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
if (Tok->is(TT_TypeDeclarationParen))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107907.365762.patch
Type: text/x-patch
Size: 1346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210811/77373854/attachment.bin>
More information about the cfe-commits
mailing list