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.

llvm-svn: 223609
This commit is contained in:
Daniel Jasper 2014-12-07 16:44:49 +00:00
parent e80523350f
commit 55aed6777f
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -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);