]> granicus.if.org Git - clang/commitdiff
clang-format: Add missing space before ObjC selector.
authorDaniel Jasper <djasper@google.com>
Fri, 15 May 2015 09:05:31 +0000 (09:05 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 15 May 2015 09:05:31 +0000 (09:05 +0000)
Before:
  [self aaaaa:(1 + 2)bbbbb:3];

After:
  [self aaaaa:(1 + 2) bbbbb:3];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237424 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 130e2c3b2ac71eca84ff8dc50942c4b97d75e477..c2992223791c427a916451ad63342e50fa8c2468 100644 (file)
@@ -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);
index d5614b84305a5085b6ece67a6f0c5a8da02f6efc..9661919f517b3fa92cdd57969dc4ff4d4072c2db 100644 (file)
@@ -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];");