Avoid breaking non-trailing block comments.
authorAlexander Kornienko <alexfh@google.com>
Tue, 16 Jul 2013 23:47:22 +0000 (23:47 +0000)
committerAlexander Kornienko <alexfh@google.com>
Tue, 16 Jul 2013 23:47:22 +0000 (23:47 +0000)
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 */);

llvm-svn: 186471

clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

index 11ab58c..125283a 100644 (file)
@@ -917,7 +917,7 @@ private:
 
       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));
index 433d0ec..3b8f911 100644 (file)
@@ -866,6 +866,13 @@ TEST_F(FormatTest, CorrectlyHandlesLengthOfBlockComments) {
              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"