[PATCH] D29383: [clang-format] Fix regression about not aligning trailing comments in case they were previously aligned, but at different indent.
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 1 02:21:24 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293755: [clang-format] Fix regression about not aligning trailing comments in case they… (authored by krasimir).
Changed prior to commit:
https://reviews.llvm.org/D29383?vs=86595&id=86596#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29383
Files:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2238,7 +2238,7 @@
EXPECT_EQ("int i; // This long\n"
" // line gets\n"
" // broken.\n"
- " // \n"
+ " //\n"
" // keep.\n",
format("int i; // This long line gets broken.\n"
" // \n"
@@ -11741,7 +11741,7 @@
EXPECT_EQ(Expected, *Result);
}
-TEST_F(FormatTest, AllignTrailingComments) {
+TEST_F(FormatTest, AlignTrailingComments) {
EXPECT_EQ("#define MACRO(V) \\\n"
" V(Rt2) /* one more char */ \\\n"
" V(Rs) /* than here */ \\\n"
@@ -11751,6 +11751,15 @@
"V(Rs) /* than here */ \\\n"
"/* comment 3 */ \\\n",
getLLVMStyleWithColumns(40)));
+ EXPECT_EQ("int i = f(abc, // line 1\n"
+ " d, // line 2\n"
+ " // line 3\n"
+ " b);",
+ format("int i = f(abc, // line 1\n"
+ " d, // line 2\n"
+ " // line 3\n"
+ " b);",
+ getLLVMStyleWithColumns(40)));
}
} // end namespace
} // end namespace format
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -803,18 +803,16 @@
ContentColumn[LineIndex] -
(Content[LineIndex].data() - Lines[LineIndex].data()) +
(OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size());
- if (tokenAt(LineIndex).OriginalColumn != LineColumn) {
- Whitespaces.replaceWhitespace(*Tokens[LineIndex],
- /*Newlines=*/1,
- /*Spaces=*/LineColumn,
- /*StartOfTokenColumn=*/LineColumn,
- /*InPPDirective=*/false);
- } else {
- // The whitespace preceding the first line of this token does not need
- // to be touched.
- Whitespaces.addUntouchableToken(tokenAt(LineIndex),
- /*InPPDirective=*/false);
- }
+
+ // We always want to create a replacement instead of adding an untouchable
+ // token, even if LineColumn is the same as the original column of the
+ // token. This is because WhitespaceManager doesn't align trailing
+ // comments if they are untouchable.
+ Whitespaces.replaceWhitespace(*Tokens[LineIndex],
+ /*Newlines=*/1,
+ /*Spaces=*/LineColumn,
+ /*StartOfTokenColumn=*/LineColumn,
+ /*InPPDirective=*/false);
}
}
if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29383.86596.patch
Type: text/x-patch
Size: 3171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170201/23a81981/attachment.bin>
More information about the cfe-commits
mailing list