unsigned Length = 0;
if (!fitsIntoLimit(I->First, Limit, &Length))
return false;
+
+ // We can never merge stuff if there are trailing line comments.
+ if (I->Last->Type == TT_LineComment)
+ return true;
+
if (Limit == Length)
return true; // Couldn't fit a space.
Limit -= Length + 1; // One space.
if (!Style.AllowShortIfStatementsOnASingleLine)
return;
AnnotatedLine &Line = *I;
+ if (Line.Last->isNot(tok::r_paren))
+ return;
if (!fitsIntoLimit((I + 1)->First, Limit))
return;
if ((I + 1)->First.is(tok::kw_if) || (I + 1)->First.Type == TT_LineComment)
verifyFormat("if (a) return;", getGoogleStyleWithColumns(14));
verifyFormat("if (a)\n return;", getGoogleStyleWithColumns(13));
verifyFormat("if (aaaaaaaaa)\n"
- " return;", getGoogleStyleWithColumns(14));
+ " return;", getGoogleStyleWithColumns(14));
+ verifyGoogleFormat("if (a) // Can't merge this\n"
+ " f();\n");
+ verifyGoogleFormat("if (a) /* still don't merge */\n"
+ " f();");
+ verifyGoogleFormat("if (a) { // Never merge this\n"
+ " f();\n"
+ "}");
+ verifyGoogleFormat("if (a) { /* Never merge this */\n"
+ " f();\n"
+ "}");
}
TEST_F(FormatTest, ParseIfElse) {