Formatter/ObjC: Correctly format casts in objc message send expressions.

llvm-svn: 184804
This commit is contained in:
Nico Weber 2013-06-25 00:55:57 +00:00
parent 503b726b43
commit ec9e41076b
2 changed files with 6 additions and 3 deletions

View File

@ -637,9 +637,8 @@ private:
// there is also an identifier before the ().
if (LeftOfParens && (LeftOfParens->Tok.getIdentifierInfo() == NULL ||
LeftOfParens->is(tok::kw_return)) &&
LeftOfParens->Type != TT_TemplateCloser &&
LeftOfParens->Type != TT_ObjCMethodExpr && Current.Next &&
(Current.Next->is(tok::identifier)))
LeftOfParens->Type != TT_TemplateCloser && Current.Next &&
Current.Next->is(tok::identifier))
IsCast = true;
if (IsCast && !ParensAreEmpty)
Current.Type = TT_CastRParen;

View File

@ -4309,6 +4309,10 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
verifyFormat("throw [self errorFor:a];");
verifyFormat("@throw [self errorFor:a];");
verifyFormat("[(id)foo bar:(id)baz quux:(id)snorf];");
verifyFormat("[(id)foo bar:(id) ? baz : quux];");
verifyFormat("4 > 4 ? (id)a : (id)baz;");
// This tests that the formatter doesn't break after "backing" but before ":",
// which would be at 80 columns.
verifyFormat(