[clang] 1116ed2 - [clang-format] Correctly count a tab's width in a comment
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 12 03:23:41 PDT 2023
Author: Björn Schäpers
Date: 2023-07-12T12:23:19+02:00
New Revision: 1116ed2beb1cd62a4b450efead481009af19df62
URL: https://github.com/llvm/llvm-project/commit/1116ed2beb1cd62a4b450efead481009af19df62
DIFF: https://github.com/llvm/llvm-project/commit/1116ed2beb1cd62a4b450efead481009af19df62.diff
LOG: [clang-format] Correctly count a tab's width in a comment
It worked only correct for a tab as the first char.
Fixes https://github.com/llvm/llvm-project/issues/56769
Differential Revision: https://reviews.llvm.org/D138402
Added:
Modified:
clang/lib/Format/BreakableToken.cpp
clang/unittests/Format/FormatTestComments.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 16df187eadbf57..af1e0748fafa97 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -82,9 +82,9 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn,
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;
}
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index b0ba00caeeb442..a5fcf60cc59e76 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -652,6 +652,11 @@ TEST_F(FormatTestComments, SplitsLongCxxComments) {
"//: 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) {
More information about the cfe-commits
mailing list