From ec9e41076b84ca0f01f0826e5375b443b39a9c5b Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 25 Jun 2013 00:55:57 +0000 Subject: [PATCH] Formatter/ObjC: Correctly format casts in objc message send expressions. llvm-svn: 184804 --- clang/lib/Format/TokenAnnotator.cpp | 5 ++--- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c6b491914b3c..c5315e72600c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 839d9ec0be38..6b1d2d3f400c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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(