Tok->Type = TT_ObjCForIn;
break;
case tok::comma:
- if (Contexts.back().FirstStartOfName)
+ if (Contexts.back().FirstStartOfName && Contexts.size() == 1) {
Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
+ Line.IsMultiVariableDeclStmt = true;
+ }
if (Contexts.back().InCtorInitializer)
Tok->Type = TT_CtorInitializerComma;
if (Contexts.back().IsForEachMacro)
TT_FunctionDeclarationName)))) &&
(Left.Tok.isLiteral() ||
(!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
- Style.PointerAlignment != FormatStyle::PAS_Left));
+ (Style.PointerAlignment != FormatStyle::PAS_Left ||
+ Line.IsMultiVariableDeclStmt)));
if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
(!Left.is(TT_PointerOrReference) ||
- Style.PointerAlignment != FormatStyle::PAS_Right))
+ (Style.PointerAlignment != FormatStyle::PAS_Right &&
+ !Line.IsMultiVariableDeclStmt)))
return true;
if (Left.is(TT_PointerOrReference))
return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
(!Right.isOneOf(TT_PointerOrReference, tok::l_paren) &&
- Style.PointerAlignment != FormatStyle::PAS_Right && Left.Previous &&
+ (Style.PointerAlignment != FormatStyle::PAS_Right &&
+ !Line.IsMultiVariableDeclStmt) &&
+ Left.Previous &&
!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
return true;
if (Right.is(TT_RangeBasedForLoopColon))
return false;
+ if (Right.is(TT_PointerOrReference) && Line.IsMultiVariableDeclStmt)
+ return true;
if (Left.isOneOf(TT_PointerOrReference, TT_TemplateCloser,
TT_UnaryOperator) ||
Left.is(tok::kw_operator))
: First(Line.Tokens.front().Tok), Level(Line.Level),
InPPDirective(Line.InPPDirective),
MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false),
- Affected(false), LeadingEmptyLinesAffected(false),
- ChildrenAffected(false) {
+ IsMultiVariableDeclStmt(false), Affected(false),
+ LeadingEmptyLinesAffected(false), ChildrenAffected(false) {
assert(!Line.Tokens.empty());
// Calculate Next and Previous for all tokens. Note that we must overwrite
bool InPPDirective;
bool MustBeDeclaration;
bool MightBeFunctionDecl;
+ bool IsMultiVariableDeclStmt;
/// \c True if this line should be formatted, i.e. intersects directly or
/// indirectly with one of the input ranges.
" *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;",
- getGoogleStyle());
- // Not ideal, but pointer-with-type does not allow much here.
- verifyGoogleFormat(
- "aaaaaaaaa* a = aaaaaaaaaaaaaaaaaaa, * b = bbbbbbbbbbbbbbbbbbb,\n"
- " * b = bbbbbbbbbbbbbbbbbbb, * d = ddddddddddddddddddd;");
+ FormatStyle Style = getGoogleStyle();
+ Style.PointerAlignment = FormatStyle::PAS_Left;
+ Style.DerivePointerAlignment = false;
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
+ " *b = bbbbbbbbbbbbbbbbbbb;",
+ Style);
+ verifyFormat(
+ "aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
+ " *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;",
+ Style);
}
TEST_F(FormatTest, ConditionalExpressionsInBrackets) {