]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect detection of ObjC "in" keyword.
authorDaniel Jasper <djasper@google.com>
Thu, 18 Dec 2014 12:11:01 +0000 (12:11 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 18 Dec 2014 12:11:01 +0000 (12:11 +0000)
Before:
  for (auto v : in [1]) { ..

After:
  for (auto v : in[1]) { ..

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

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

index deda40cab891b84e6308cf65160d2d8d2ea54a20..2e97ffffbece503f28e4794257363aa354a8ffbe 100644 (file)
@@ -511,7 +511,8 @@ private:
       parseTemplateDeclaration();
       break;
     case tok::identifier:
-      if (Line.First->is(tok::kw_for) && Tok->is(Keywords.kw_in))
+      if (Line.First->is(tok::kw_for) && Tok->is(Keywords.kw_in) &&
+          Tok->Previous->isNot(tok::colon))
         Tok->Type = TT_ObjCForIn;
       break;
     case tok::comma:
index 743f501b0d18c32daf53d4e45765c5cb4f17e473..66835d74b3b4beda81ff12218f5eb270a54d7195 100644 (file)
@@ -6781,6 +6781,7 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
   // Whew!
 
   verifyFormat("return in[42];");
+  verifyFormat("for (auto v : in[1]) {\n}");
   verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"
                "}");
   verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");