From: Alexander Kornienko Date: Tue, 16 Jul 2013 23:47:22 +0000 (+0000) Subject: Avoid breaking non-trailing block comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4b4a52f1c3b768473169bc7cb450d406e1b495c;p=clang 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 11ab58c18c..125283a0c6 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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)); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 433d0ec1d7..3b8f91130f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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"