Call mightFitOneOneline() on the line before the closing brace only
if it is at the level of the block.
Differential Revision: https://reviews.llvm.org/
D127614
size_t PPStartHash = computePPHash();
- unsigned InitialLevel = Line->Level;
+ const unsigned InitialLevel = Line->Level;
nextToken(/*LevelDifference=*/AddLevels);
// Bail out if there are too many levels. Otherwise, the stack might overflow.
return false;
}
assert(!CurrentLines->empty());
- if (!mightFitOnOneLine(CurrentLines->back()))
+ auto &LastLine = CurrentLines->back();
+ if (LastLine.Level == InitialLevel + 1 && !mightFitOnOneLine(LastLine))
return false;
if (Tok->is(TT_ElseLBrace))
return true;
"}",
Style);
+ verifyFormat("if (a)\n"
+ " b;\n"
+ "else if (c) {\n"
+ " d;\n"
+ " e;\n"
+ "} else\n"
+ " f = g(foo, bar,\n"
+ " baz);",
+ "if (a)\n"
+ " b;\n"
+ "else {\n"
+ " if (c) {\n"
+ " d;\n"
+ " e;\n"
+ " } else\n"
+ " f = g(foo, bar, baz);\n"
+ "}",
+ Style);
+
Style.ColumnLimit = 0;
verifyFormat("if (a)\n"
" b234567890223456789032345678904234567890 = "