r186471 - Avoid breaking non-trailing block comments.
Alexander Kornienko
alexfh at google.com
Tue Jul 16 16:47:23 PDT 2013
Author: alexfh
Date: Tue Jul 16 18:47:22 2013
New Revision: 186471
URL: http://llvm.org/viewvc/llvm-project?rev=186471&view=rev
Log:
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 */);
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=186471&r1=186470&r2=186471&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Jul 16 18:47:22 2013
@@ -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));
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=186471&r1=186470&r2=186471&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul 16 18:47:22 2013
@@ -866,6 +866,13 @@ TEST_F(FormatTest, CorrectlyHandlesLengt
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"
More information about the cfe-commits
mailing list