]> granicus.if.org Git - clang/commitdiff
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 */);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186471 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 11ab58c18cde728c7db504e0ec0940706f57ef00..125283a0c6dd6a5a6b8884fd2b40660b7539940c 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 433d0ec1d719559df4411e0811886178b19ae2c2..3b8f91130ff4a7d9d2c6bf33d8248ca9797bd6f3 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"