From cdb58b2e4537a5369015327cf5b210e582b115a5 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 15 May 2015 09:05:31 +0000 Subject: [PATCH] clang-format: Add missing space before ObjC selector. Before: [self aaaaa:(1 + 2)bbbbb:3]; After: [self aaaaa:(1 + 2) bbbbb:3]; llvm-svn: 237424 --- clang/lib/Format/TokenAnnotator.cpp | 7 ++++++- clang/unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 130e2c3b2ac7..c2992223791c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1922,8 +1922,13 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, } if (Left.is(TT_UnaryOperator)) return Right.is(TT_BinaryOperator); + + // If the next token is a binary operator or a selector name, we have + // incorrectly classified the parenthesis as a cast. FIXME: Detect correctly. if (Left.is(TT_CastRParen)) - return Style.SpaceAfterCStyleCast || Right.is(TT_BinaryOperator); + return Style.SpaceAfterCStyleCast || + Right.isOneOf(TT_BinaryOperator, TT_SelectorName); + if (Left.is(tok::greater) && Right.is(tok::greater)) { return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) && (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d5614b84305a..9661919f517b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7216,6 +7216,8 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { verifyFormat("for (id foo in [self getStuffFor:bla]) {\n" "}"); verifyFormat("[self aaaaa:MACRO(a, b:, c:)];"); + verifyFormat("[self aaaaa:(1 + 2) bbbbb:3];"); + verifyFormat("[self aaaaa:(Type)a bbbbb:3];"); verifyFormat("[self stuffWithInt:(4 + 2) float:4.5];"); verifyFormat("[self stuffWithInt:a ? b : c float:4.5];");