if (!State.NextToken || !State.NextToken->Previous)
return 0;
FormatToken &Current = *State.NextToken;
- const FormatToken &Previous = *State.NextToken->Previous;
+ const FormatToken &Previous = *Current.Previous;
// If we are continuing an expression, we want to use the continuation indent.
unsigned ContinuationIndent =
std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) +
// Indent from 'LastSpace' unless this the fake parentheses encapsulating a
// builder type call after 'return'. If such a call is line-wrapped, we
// commonly just want to indent from the start of the line.
- if (!Previous || Previous->isNot(tok::kw_return) || *I > 0)
+ if (!Current.isTrailingComment() &&
+ (!Previous || Previous->isNot(tok::kw_return) || *I > 0))
NewParenState.Indent =
std::max(std::max(State.Column, NewParenState.Indent),
State.Stack.back().LastSpace);
// other expression, unless the indentation needs to be skipped.
if (*I == prec::Conditional ||
(!SkipFirstExtraIndent && *I > prec::Assignment &&
- !Style.BreakBeforeBinaryOperators))
+ !Current.isTrailingComment() && !Style.BreakBeforeBinaryOperators))
NewParenState.Indent += Style.ContinuationIndentWidth;
if ((Previous && !Previous->opensScope()) || *I > prec::Comma)
NewParenState.BreakBeforeParameter = false;
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" // Comment inside a statement.\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
+ verifyFormat("SomeFunction(a,\n"
+ " // comment\n"
+ " b + x);");
+ verifyFormat("SomeFunction(a, a,\n"
+ " // comment\n"
+ " b + x);");
verifyFormat(
"bool aaaaaaaaaaaaa = // comment\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"