Author: wizard Date: Fri Nov 9 15:19:14 2018 New Revision: 346566 URL: http://llvm.org/viewvc/llvm-project?rev=346566&view=rev Log: Fix ClangFormat issue of recognizing ObjC subscript as C++ attributes when message target is a result of a C-style method.
Summary: The issue is that for array subscript like: ``` arr[[Foo() bar]]; ``` ClangFormat will recognize it as C++11 attribute syntax and put a space between 'arr' and first '[', like: ``` arr [[Foo() bar]]; ``` Now it is fixed. Tested with: ``` ninja FormatTests ``` Reviewers: benhamilton Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54288 Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=346566&r1=346565&r2=346566&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Nov 9 15:19:14 2018 @@ -366,7 +366,8 @@ private: // specifier parameter, although this is technically valid: // [[foo(:)]] if (AttrTok->is(tok::colon) || - AttrTok->startsSequence(tok::identifier, tok::identifier)) + AttrTok->startsSequence(tok::identifier, tok::identifier) || + AttrTok->startsSequence(tok::r_paren, tok::identifier)) return false; if (AttrTok->is(tok::ellipsis)) return true; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=346566&r1=346565&r2=346566&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 9 15:19:14 2018 @@ -6472,6 +6472,8 @@ TEST_F(FormatTest, UnderstandsSquareAttr // Make sure we do not mistake attributes for array subscripts. verifyFormat("int a() {}\n" "[[unused]] int b() {}\n"); + verifyFormat("NSArray *arr;\n" + "arr[[Foo() bar]];"); // On the other hand, we still need to correctly find array subscripts. verifyFormat("int a = std::vector<int>{1, 2, 3}[0];"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits