From: Nico Weber Date: Tue, 25 Jun 2013 00:55:57 +0000 (+0000) Subject: Formatter/ObjC: Correctly format casts in objc message send expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=465e8615a153ebd70eb27785af79f7e82e4a81d4;p=clang Formatter/ObjC: Correctly format casts in objc message send expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184804 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c6b491914b..c5315e7260 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 839d9ec0be..6b1d2d3f40 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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(