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

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 2 06:01:12 PDT 2021


krasimir created this revision.
krasimir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

https://reviews.llvm.org/D105964 updated the detection of function
definitions. It had the unfortunate effect to start marking object
definitions with attribute-like macros as function definitions.

This addresses this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107269

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
@@ -8235,6 +8235,11 @@
                "  return a + b < c;\n"
                "}",
                Style);
+  // The return breaking style doesn't affect object definitions with
+  // attribute-like macros.
+  verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
+               "    ABSL_GUARDED_BY(mutex) = {};",
+               getGoogleStyleWithColumns(40));
 
   Style = getGNUStyle();
 
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2482,7 +2482,8 @@
   //     return i + 1;
   //   }
   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;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
        Tok = Tok->Next) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107269.363460.patch
Type: text/x-patch
Size: 1197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210802/a2c9d907/attachment.bin>


More information about the cfe-commits mailing list