[PATCH] D124260: [clang-format] ColumnLimit check for trailing comments alignment acts wrong for multi-byte UTF-8 #47624
Александр Тулуп via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 23 17:10:06 PDT 2022
StailGot updated this revision to Diff 424754.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124260/new/
https://reviews.llvm.org/D124260
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTestComments.cpp
Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -2856,6 +2856,13 @@
"int a; //\n");
verifyFormat("/**/ //\n"
"int a; //\n");
+
+ // https://llvm.org/PR48280
+ EXPECT_EQ("int ab; // utf8 🐉\n"
+ "int a; // line\n",
+ format("int ab; // long 🐉\n"
+ "int a; // line\n",
+ getLLVMStyleWithColumns(17)));
}
TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -909,8 +909,8 @@
if (Style.ColumnLimit == 0)
ChangeMaxColumn = UINT_MAX;
- else if (Style.ColumnLimit >= Changes[i].TokenLength)
- ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+ else if (Style.ColumnLimit >= Changes[i].Tok->ColumnWidth)
+ ChangeMaxColumn = Style.ColumnLimit - Changes[i].Tok->ColumnWidth;
else
ChangeMaxColumn = ChangeMinColumn;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124260.424754.patch
Type: text/x-patch
Size: 1255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220424/d7ccbe4e/attachment.bin>
More information about the cfe-commits
mailing list