State.Stack.back().ContainsUnwrappedBuilder = true;
State.Column += Spaces;
- if (Current.is(tok::l_paren) && Previous.isOneOf(tok::kw_if, tok::kw_for))
+ if (Current.isNot(tok::comment) && Previous.is(tok::l_paren) &&
+ Previous.Previous && Previous.Previous->isOneOf(tok::kw_if, tok::kw_for))
// Treat the condition inside an if as if it was a second function
// parameter, i.e. let nested calls have a continuation indent.
- State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(".
+ State.Stack.back().LastSpace = State.Column;
else if (Current.isNot(tok::comment) &&
(Previous.is(tok::comma) ||
(Previous.is(tok::colon) && Previous.Type == TT_ObjCMethodExpr)))
return false;
if (Left.is(tok::l_paren) && Left.Previous &&
(Left.Previous->Type == TT_BinaryOperator ||
- Left.Previous->Type == TT_CastRParen))
+ Left.Previous->Type == TT_CastRParen || Left.Previous->is(tok::kw_if)))
return false;
if (Right.Type == TT_ImplicitStringLiteral)
return false;
"else {\n"
" g()\n"
"}");
+
+ verifyFormat("if (a) {\n"
+ "} else if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaa)) {\n"
+ "}");
}
TEST_F(FormatTest, FormatsForLoop) {
" int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
" int jjjjjjjjjjjjjjjjjjjjjjjj; /* */",
getLLVMStyleWithColumns(61));
+
+ verifyFormat("if ( // This is some comment\n"
+ " x + 3) {\n"
+ "}");
+ EXPECT_EQ("if ( // This is some comment\n"
+ " // spanning two lines\n"
+ " x + 3) {\n"
+ "}",
+ format("if( // This is some comment\n"
+ " // spanning two lines\n"
+ " x + 3) {\n"
+ "}"));
}
TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {