From: Daniel Jasper Date: Thu, 18 Dec 2014 12:11:01 +0000 (+0000) Subject: clang-format: Fix incorrect detection of ObjC "in" keyword. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c795c9375335168923d21d100b53d32d861cab1;p=clang clang-format: Fix incorrect detection of ObjC "in" keyword. 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index deda40cab8..2e97ffffbe 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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: diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 743f501b0d..66835d74b3 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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:)];");