[PATCH] D138402: [clang-format] Correctly count a tab's width in a comment

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 20 23:25:32 PST 2022


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

It worked only correct for a tab as the first char.

Fixes https://github.com/llvm/llvm-project/issues/56769


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138402

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestComments.cpp


Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -729,6 +729,11 @@
             "//: one line",
             format("//: A comment that doesn't fit on one line",
                    getLLVMStyleWithColumns(20)));
+
+  verifyFormat(
+      "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth()\n"
+      "//* 0.2)",
+      "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth() * 0.2)");
 }
 
 TEST_F(FormatTestComments, PreservesHangingIndentInCxxComments) {
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -82,9 +82,9 @@
        NumChars < MaxSplit && MaxSplitBytes < Text.size();) {
     unsigned BytesInChar =
         encoding::getCodePointNumBytes(Text[MaxSplitBytes], Encoding);
-    NumChars +=
-        encoding::columnWidthWithTabs(Text.substr(MaxSplitBytes, BytesInChar),
-                                      ContentStartColumn, TabWidth, Encoding);
+    NumChars += encoding::columnWidthWithTabs(
+        Text.substr(MaxSplitBytes, BytesInChar), ContentStartColumn + NumChars,
+        TabWidth, Encoding);
     MaxSplitBytes += BytesInChar;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138402.476808.patch
Type: text/x-patch
Size: 1393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221121/5d5bd00b/attachment.bin>


More information about the cfe-commits mailing list