Avoid breaking non-trailing block comments.
Motivating example:
// column limit ------------------->
void ffffffffffff(int aaaaaa /* test */);
Formatting before the patch:
void ffffffffffff(int aaaaaa /* test
*/);
Formatting after the patch:
void
ffffffffffff(int aaaaaa /* test */);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186471 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 11ab58c..125283a 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -917,7 +917,7 @@
Token.reset(new BreakableStringLiteral(Current, StartColumn,
Line.InPPDirective, Encoding));
- } else if (Current.Type == TT_BlockComment) {
+ } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) {
Token.reset(new BreakableBlockComment(
Style, Current, StartColumn, OriginalStartColumn, !Current.Previous,
Line.InPPDirective, Encoding));
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 433d0ec..3b8f911 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -866,6 +866,13 @@
getLLVMStyleWithColumns(40)));
}
+TEST_F(FormatTest, DontBreakNonTrailingBlockComments) {
+ EXPECT_EQ("void\n"
+ "ffffffffff(int aaaaa /* test */);",
+ format("void ffffffffff(int aaaaa /* test */);",
+ getLLVMStyleWithColumns(35)));
+}
+
TEST_F(FormatTest, SplitsLongCxxComments) {
EXPECT_EQ("// A comment that\n"
"// doesn't fit on\n"