return false;
if (Left.is(tok::colon))
return Left.Type != TT_ObjCMethodExpr;
+ if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
+ return !Left.Children.empty(); // No spaces in "{}".
+ if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
+ (Right.is(tok::r_brace) && Right.MatchingParen &&
+ Right.MatchingParen->BlockKind != BK_Block))
+ return !Style.Cpp11BracedListStyle;
if (Left.Type == TT_BlockComment)
return !Left.TokenText.endswith("=*/");
if (Right.is(tok::l_paren)) {
}
if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword)
return false;
- if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
- return !Left.Children.empty(); // No spaces in "{}".
- if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
- (Right.is(tok::r_brace) && Right.MatchingParen &&
- Right.MatchingParen->BlockKind != BK_Block))
- return !Style.Cpp11BracedListStyle;
if (Right.Type == TT_UnaryOperator)
return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
(Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr);
return true;
}
- // If the last token before a '}' is a comma or a comment, the intention is to
- // insert a line break after it in order to make shuffling around entries
- // easier.
+ // If the last token before a '}' is a comma or a trailing comment, the
+ // intention is to insert a line break after it in order to make shuffling
+ // around entries easier.
const FormatToken *BeforeClosingBrace = nullptr;
if (Left.is(tok::l_brace) && Left.MatchingParen)
BeforeClosingBrace = Left.MatchingParen->Previous;
else if (Right.is(tok::r_brace))
BeforeClosingBrace = Right.Previous;
- if (BeforeClosingBrace &&
- BeforeClosingBrace->isOneOf(tok::comma, tok::comment))
+ if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
+ BeforeClosingBrace->isTrailingComment()))
return true;
if (Style.Language == FormatStyle::LK_JavaScript) {
verifyFormat("int foo(int i) { return fo1{}(i); }");
verifyFormat("int foo(int i) { return fo1{}(i); }");
verifyFormat("auto i = decltype(x){};");
+ verifyFormat("std::vector<int> v = {1, 0 /* comment */};");
// In combination with BinPackParameters = false.
FormatStyle NoBinPacking = getLLVMStyle();
" bbbbbbbbbbbbbbbbbbbb, bbbbb };",
ExtraSpaces);
verifyFormat("DoSomethingWithVector({} /* No data */);", ExtraSpaces);
- verifyFormat("DoSomethingWithVector({\n"
- " {} /* No data */\n"
- " },\n"
- " { { 1, 2 } });",
+ verifyFormat("DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });",
ExtraSpaces);
verifyFormat(
"someFunction(OtherParam,\n"
" 1, 1, 1, 1, 1, 1, 1, 1, //\n"
"};",
getLLVMStyleWithColumns(39));
- verifyFormat("vector<int> x = {\n"
- " 1, 1, 1, 1, 1, 1, 1, 1,\n"
- " /**/ /**/\n"
- "};",
+ verifyFormat("vector<int> x = {1, 1, 1, 1,\n"
+ " 1, 1, 1, 1,\n"
+ " /**/ /**/};",
getLLVMStyleWithColumns(39));
verifyFormat("return {{aaaaaaaaaaaaaaaaaaaaa},\n"
" {aaaaaaaaaaaaaaaaaaa},\n"