[PATCH] D107269: [clan-format] detect function definitions more conservatively

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 3 02:55:07 PDT 2021


krasimir added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:2485-2486
   if (Next->Next && Next->Next->is(tok::identifier) &&
-      !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi)))
+      (!Next->MatchingParen->Next ||
+       Next->MatchingParen->Next->is(tok::l_brace)))
     return true;
----------------
owenpan wrote:
> I was contemplating the above in https://reviews.llvm.org/D105964 and should have used it instead. This is probably more conservative and accurate than checking for an `l_brace` following the `r_paren`.
Thank you! 

Applied the suggestion. I was a bit worried that this suggestion won't work for function definitions with a trailing semicolon, but there the semicolon is not part of the same line as the function name, so all is good there. Added a few tests for this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107269/new/

https://reviews.llvm.org/D107269



More information about the cfe-commits mailing list