owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks, 
pjessesco.
owenpan added a project: clang-format.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117759

Files:
  clang/lib/Format/FormatTokenLexer.cpp


Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -430,19 +430,15 @@
     return false;
 
   auto First = Tokens.end() - 3;
-  bool FourthTokenIsLess = false;
+  auto X = Tokens.size() > 3 ? First[-1] : nullptr;
+  auto Y = First[2];
 
-  if (Tokens.size() > 3) {
-    auto Fourth = (Tokens.end() - 4)[0];
-    FourthTokenIsLess = Fourth->is(tok::less);
-
-    // Do not remove a whitespace between the two "<" e.g. "operator< <>".
-    if (First[2]->is(tok::greater) && Fourth->is(tok::kw_operator))
-      return false;
-  }
+  // Do not remove a whitespace between the two "<" e.g. "operator< <>".
+  if (Y->is(tok::greater) && X && X->is(tok::kw_operator))
+    return false;
 
-  if (First[2]->is(tok::less) || First[1]->isNot(tok::less) ||
-      First[0]->isNot(tok::less) || FourthTokenIsLess)
+  if (Y->is(tok::less) || First[1]->isNot(tok::less) ||
+      First[0]->isNot(tok::less) || (X && X->is(tok::less)))
     return false;
 
   // Only merge if there currently is no whitespace between the two "<".


Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -430,19 +430,15 @@
     return false;
 
   auto First = Tokens.end() - 3;
-  bool FourthTokenIsLess = false;
+  auto X = Tokens.size() > 3 ? First[-1] : nullptr;
+  auto Y = First[2];
 
-  if (Tokens.size() > 3) {
-    auto Fourth = (Tokens.end() - 4)[0];
-    FourthTokenIsLess = Fourth->is(tok::less);
-
-    // Do not remove a whitespace between the two "<" e.g. "operator< <>".
-    if (First[2]->is(tok::greater) && Fourth->is(tok::kw_operator))
-      return false;
-  }
+  // Do not remove a whitespace between the two "<" e.g. "operator< <>".
+  if (Y->is(tok::greater) && X && X->is(tok::kw_operator))
+    return false;
 
-  if (First[2]->is(tok::less) || First[1]->isNot(tok::less) ||
-      First[0]->isNot(tok::less) || FourthTokenIsLess)
+  if (Y->is(tok::less) || First[1]->isNot(tok::less) ||
+      First[0]->isNot(tok::less) || (X && X->is(tok::less)))
     return false;
 
   // Only merge if there currently is no whitespace between the two "<".
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to