}
} else {
if (Current.is(tok::equal) &&
- (RootToken.is(tok::kw_for) || State.ParenLevel == 0)) {
- State.Stack.back().VariablePos =
- State.Column - Previous.FormatTok.TokenLength;
+ (RootToken.is(tok::kw_for) || State.ParenLevel == 0) &&
+ State.Stack.back().VariablePos == 0) {
+ State.Stack.back().VariablePos = State.Column;
+ // Move over * and & if they are bound to the variable name.
+ const AnnotatedToken *Tok = &Previous;
+ while (Tok &&
+ State.Stack.back().VariablePos >= Tok->FormatTok.TokenLength) {
+ State.Stack.back().VariablePos -= Tok->FormatTok.TokenLength;
+ if (Tok->SpacesRequiredBefore != 0)
+ break;
+ Tok = Tok->Parent;
+ }
if (Previous.PartOfMultiVariableDeclStmt)
State.Stack.back().LastSpace = State.Stack.back().VariablePos;
}
"bool aaaaaaaaaaaaaaaaaaaaa =\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbb && cccccccccccccccccccccccccccc,\n"
" d = e && f;");
-
+ verifyFormat("aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,\n"
+ " c = cccccccccccccccccccc, d = dddddddddddddddddddd;");
+ verifyFormat("aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
+ " *c = ccccccccccccccccccc, *d = ddddddddddddddddddd;");
+ verifyFormat("aaaaaaaaa ***a = aaaaaaaaaaaaaaaaaaa, ***b = bbbbbbbbbbbbbbb,\n"
+ " ***c = ccccccccccccccccccc, ***d = ddddddddddddddd;");
+ // FIXME: If multiple variables are defined, the "*" needs to move to the new
+ // line. Also fix indent for breaking after the type, this looks bad.
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
+ " *b = bbbbbbbbbbbbbbbbbbb;");
+
+ // Not ideal, but pointer-with-type does not allow much here.
+ verifyGoogleFormat(
+ "aaaaaaaaa* a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
+ " *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;");
}
TEST_F(FormatTest, ConditionalExpressionsInBrackets) {