[PATCH] D25439: Fixed column shift when formatting line containing bit shift operators

Paweł Żukowski via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 12 11:57:21 PDT 2016


idlecode updated this revision to Diff 74412.

https://reviews.llvm.org/D25439

Files:
  lib/Format/FormatTokenLexer.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11361,6 +11361,16 @@
                "aaaallvm::outs()\n    <<");
 }
 
+TEST_F(FormatTest, BitshiftOperatorWidth) {
+  std::string left = "int a = 1 << 2; /* foo\n"
+                     "                   bar */";
+  EXPECT_EQ(left, format(left));
+
+  std::string right = "int b = 256 >> 2; /* foo\n"
+                      "                     bar */";
+  EXPECT_EQ(right, format(right));
+}
+
 TEST_F(FormatTest, HandleUnbalancedImplicitBracesAcrossPPBranches) {
   std::string code = "#if A\n"
                      "#if B\n"
Index: lib/Format/FormatTokenLexer.cpp
===================================================================
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -525,10 +525,12 @@
   } else if (FormatTok->Tok.is(tok::greatergreater)) {
     FormatTok->Tok.setKind(tok::greater);
     FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
+    Column += 1;
     StateStack.push(LexerState::TOKEN_STASHED);
   } else if (FormatTok->Tok.is(tok::lessless)) {
     FormatTok->Tok.setKind(tok::less);
     FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
+    Column += 1;
     StateStack.push(LexerState::TOKEN_STASHED);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25439.74412.patch
Type: text/x-patch
Size: 1373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161012/f09eb2d9/attachment.bin>


More information about the cfe-commits mailing list