[PATCH] D137762: [clang-format] avoid breaking )( with BlockIndent

Gedare Bloom via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 9 20:44:08 PST 2022


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

The BracketAlignmentStyle BAS_BlockIndent was forcing breaks before a
closing right parenthesis yielding strange-looking results in case of
code structures that have a left parens immediately following a right
parens ")(" such as is seen with indirect function calls via function
pointers and with type casting.

See GitHub issues #57250 and #58496.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137762

Files:
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5001,7 +5001,10 @@
       return false;
     }
     const FormatToken *Previous = Right.MatchingParen->Previous;
-    return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
+    // avoid breaking when there is an opening parens immediately following
+    // a closing parens, such as in cast operators and indirect function calls
+    return !((Previous && (Previous->is(tok::kw_for) || Previous->isIf())) ||
+             (Right.Next && Right.Next->is(tok::l_paren)));
   }
 
   // Allow breaking after a trailing annotation, e.g. after a method


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137762.474422.patch
Type: text/x-patch
Size: 758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221110/acfed36a/attachment.bin>


More information about the cfe-commits mailing list