]> granicus.if.org Git - clang/commitdiff
clang-format: Fixed missing space between Obj-C for/in and a typecast.
authorDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 15:09:08 +0000 (15:09 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 15:09:08 +0000 (15:09 +0000)
Fixes this bug: https://llvm.org/bugs/show_bug.cgi?id=24504

TokenAnnotator::spaceRequiredBetween was handling TT_ForEachMacro but
not TT_ObjCForIn, so lines that look like:

  for (id nextObject in (NSArray *)myArray)

would incorrectly turn into:

  for (id nextObject in(NSArray *)myArray)

Patch by Kent Sutherland, thank you.

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

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

index e9a78d8f66109287ccb25935321f2da405ff15cb..bcd50a88bcd30d887f05595d508e51f19d9b94e8 100644 (file)
@@ -1902,7 +1902,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
            (Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
             (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
-                          tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
+                          tok::kw_switch, tok::kw_case, TT_ForEachMacro,
+                          TT_ObjCForIn) ||
              (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
                            tok::kw_new, tok::kw_delete) &&
               (!Left.Previous || Left.Previous->isNot(tok::period))))) ||
index 5f94c21f3cce1ae1a7c5e71ce2488facf5a0f4df..3cf181ed484fa900e1f3d1d4eb91b88682f24dac 100644 (file)
@@ -7446,6 +7446,19 @@ TEST_F(FormatTest, ObjCSnippets) {
                "@import baz;");
 }
 
+TEST_F(FormatTest, ObjCForIn) {
+  verifyFormat("- (void)test {\n"
+               "  for (NSString *n in arrayOfStrings) {\n"
+               "    foo(n);\n"
+               "  }\n"
+               "}");
+  verifyFormat("- (void)test {\n"
+               "  for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"
+               "    foo(n);\n"
+               "  }\n"
+               "}");
+}
+
 TEST_F(FormatTest, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");