: Indent(Indent), LastSpace(LastSpace), FirstLessLess(0),
BreakBeforeClosingBrace(false), QuestionColumn(0),
AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),
- HasMultiParameterLine(HasMultiParameterLine), ColonPos(0) {
+ HasMultiParameterLine(HasMultiParameterLine), ColonPos(0),
+ BreakBeforeThirdOperand(false) {
}
/// \brief The position to which a specific parenthesis level needs to be
/// \brief The position of the colon in an ObjC method declaration/call.
unsigned ColonPos;
+
+ /// \brief Break before third operand in ternary expression.
+ bool BreakBeforeThirdOperand;
bool operator<(const ParenState &Other) const {
if (Indent != Other.Indent)
return HasMultiParameterLine;
if (ColonPos != Other.ColonPos)
return ColonPos < Other.ColonPos;
+ if (BreakBeforeThirdOperand != Other.BreakBeforeThirdOperand)
+ return BreakBeforeThirdOperand;
return false;
}
};
State.Column = State.Stack.back().Indent;
}
+ if (Current.is(tok::question))
+ State.Stack.back().BreakBeforeThirdOperand = true;
if (Previous.is(tok::comma) && !State.Stack.back().AvoidBinPacking)
State.Stack.back().BreakBeforeParameter = false;
(State.NextToken->Parent->ClosesTemplateDeclaration &&
State.ParenLevel == 0)))
return true;
+ if (State.NextToken->is(tok::colon) &&
+ State.Stack.back().BreakBeforeThirdOperand)
+ return true;
return false;
}
" : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " ? aaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " : aaaaaaaaaaaaaaaaaaaaaaaaaaa;");
+
+ // FIXME: The trailing third parameter here is kind of hidden. Prefer putting
+ // it on the next line.
verifyFormat(
- "unsigned Indent = formatFirstToken(\n"
- " TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
- " ? IndentForLevel[TheLine.Level] : TheLine * 2,\n"
- " TheLine.InPPDirective, PreviousEndOfLineColumn);");
+ "unsigned Indent =\n"
+ " format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
+ " ? IndentForLevel[TheLine.Level]\n"
+ " : TheLine * 2, TheLine.InPPDirective,\n"
+ " PreviousEndOfLineColumn);", getLLVMStyleWithColumns(70));
+
}
TEST_F(FormatTest, DeclarationsOfMultipleVariables) {