[PATCH] D141959: [clang-format] Fix inconsistent identification of operator&

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 4 03:59:13 PST 2023


owenpan accepted this revision.
owenpan added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:123
 private:
+  ScopeType getScopeType(FormatToken &Token) {
+    switch (Token.getType()) {
----------------
As suggested before.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1195-1198
+      // Handle unbalanced braces.
+      if (!Scopes.empty())
+        Scopes.pop_back();
       // Lines can start with '}'.
----------------
dkt01 wrote:
> owenpan wrote:
> > dkt01 wrote:
> > > owenpan wrote:
> > > > I don't think it's about unbalanced braces here.
> > > `if (!Scopes.empty())` handles unbalanced braces.  `if(Tok->Previous)` handles the case where a line starts with an rbrace.
> > I can't think of an example. Do you have one?
> The format unit test `FormatUnbalancedStructuralElements` feeds in strings that have only right braces, so without this check the pop fails.
Thanks!


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

https://reviews.llvm.org/D141959



More information about the cfe-commits mailing list