r223609 - clang-format: Don't merge lines with comments.
Daniel Jasper
djasper at google.com
Sun Dec 7 08:44:49 PST 2014
Author: djasper
Date: Sun Dec 7 10:44:49 2014
New Revision: 223609
URL: http://llvm.org/viewvc/llvm-project?rev=223609&view=rev
Log:
clang-format: Don't merge lines with comments.
Before:
int f() { // comment return 42; }
After:
int f() { // comment
return 42;
}
This fixes llvm.org/PR21769.
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=223609&r1=223608&r2=223609&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun Dec 7 10:44:49 2014
@@ -665,6 +665,9 @@ public:
}
if (I[1]->First->is(TT_FunctionLBrace) &&
Style.BreakBeforeBraces != FormatStyle::BS_Attach) {
+ if (I[1]->Last->is(TT_LineComment))
+ return 0;
+
// Check for Limit <= 2 to account for the " {".
if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(TheLine)))
return 0;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=223609&r1=223608&r2=223609&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Dec 7 10:44:49 2014
@@ -8372,6 +8372,11 @@ TEST_F(FormatTest, AllmanBraceBreaking)
" [object someMethod:@{ @\"a\" : @\"b\" }];\n"
"}",
AllmanBraceStyle);
+ verifyFormat("int f()\n"
+ "{ // comment\n"
+ " return 42;\n"
+ "}",
+ AllmanBraceStyle);
AllmanBraceStyle.ColumnLimit = 19;
verifyFormat("void f() { int i; }", AllmanBraceStyle);
More information about the cfe-commits
mailing list