[PATCH] D155783: [clang-format] Fix variable lacks of blank when previous operator is star

cqak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 19 23:21:21 PDT 2023


cqak updated this revision to Diff 542316.
cqak added a comment.

add test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155783

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
@@ -93,6 +93,9 @@
                    "\r\n"
                    "*/\r\n"));
   EXPECT_EQ(0, ReplacementCount);
+  EXPECT_EQ("x*y",
+            format("x * y"));
+  EXPECT_EQ(2, ReplacementCount);
 }
 
 TEST_F(FormatTest, RemovesEmptyLines) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2556,7 +2556,7 @@
     if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
       return TT_UnaryOperator;
 
-    if (PrevToken->Tok.isLiteral() ||
+    if (PrevToken->Tok.isLiteral() || PrevToken->Tok.isAnyIdentifier() ||
         PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
                            tok::kw_false, tok::r_brace)) {
       return TT_BinaryOperator;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155783.542316.patch
Type: text/x-patch
Size: 1046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230720/a6e78753/attachment.bin>


More information about the cfe-commits mailing list