[PATCH] D29329: [clang-format] Fix regression about adding leading whitespace to the content of line comments
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 31 07:51:40 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293641: [clang-format] Fix regression about adding leading whitespace to the content of… (authored by krasimir).
Changed prior to commit:
https://reviews.llvm.org/D29329?vs=86435&id=86437#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29329
Files:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -796,10 +796,13 @@
} else {
// This is the first line for the current token, but no reflow with the
// previous token is necessary. However, we still may need to adjust the
- // start column.
+ // start column. Note that ContentColumn[LineIndex] is the expected
+ // content column after a possible update to the prefix, hence the prefix
+ // length change is included.
unsigned LineColumn =
ContentColumn[LineIndex] -
- (Content[LineIndex].data() - Lines[LineIndex].data());
+ (Content[LineIndex].data() - Lines[LineIndex].data()) +
+ (OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size());
if (tokenAt(LineIndex).OriginalColumn != LineColumn) {
Whitespaces.replaceWhitespace(*Tokens[LineIndex],
/*Newlines=*/1,
@@ -813,13 +816,14 @@
/*InPPDirective=*/false);
}
}
- } else if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) {
- // This is not the first line of the token. Adjust the prefix if necessary.
+ }
+ if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) {
+ // Adjust the prefix if necessary.
// Take care of the space possibly introduced after a decoration.
assert(Prefix[LineIndex] == (OriginalPrefix[LineIndex] + " ").str() &&
- "Expecting a block comment decoration to differ from original by "
- "at most a space");
+ "Expecting a line comment prefix to differ from original by at most "
+ "a space");
Whitespaces.replaceWhitespaceInToken(
tokenAt(LineIndex), OriginalPrefix[LineIndex].size(), 0, "", "",
/*InPPDirective=*/false, /*Newlines=*/0, /*Spaces=*/1);
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1371,6 +1371,25 @@
format("//Even if it makes the line exceed the column limit",
getLLVMStyleWithColumns(51)));
EXPECT_EQ("//--But not here", format("//--But not here", getLLVMStyle()));
+ EXPECT_EQ("/// line 1\n"
+ "// add leading whitespace",
+ format("/// line 1\n"
+ "//add leading whitespace",
+ getLLVMStyleWithColumns(30)));
+ EXPECT_EQ("/// line 1\n"
+ "/// line 2\n"
+ "//! line 3\n"
+ "//! line 4\n"
+ "//! line 5\n"
+ "// line 6\n"
+ "// line 7",
+ format("///line 1\n"
+ "///line 2\n"
+ "//! line 3\n"
+ "//!line 4\n"
+ "//!line 5\n"
+ "// line 6\n"
+ "//line 7", getLLVMStyleWithColumns(20)));
EXPECT_EQ("// aa bb cc dd",
format("// aa bb cc dd ",
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29329.86437.patch
Type: text/x-patch
Size: 3168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170131/2fb7dbb2/attachment-0001.bin>
More information about the cfe-commits
mailing list