summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan Zhang <ynzhang@google.com>2018-11-09 23:19:14 +0000
committerYan Zhang <ynzhang@google.com>2018-11-09 23:19:14 +0000
commite2d56dcc038b4202ef36db1f423fb8ba894a0469 (patch)
tree9f877751c12dfb4bf55151197072df2928da48a3
parent6fddb536853c6485bf8dcbc9dd5d04cf9045cc6d (diff)
downloadbcm5719-llvm-e2d56dcc038b4202ef36db1f423fb8ba894a0469.tar.gz
bcm5719-llvm-e2d56dcc038b4202ef36db1f423fb8ba894a0469.zip
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 llvm-svn: 346566
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTest.cpp2
2 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 6f9b71b4b1e..501a150f848 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 635a34499da..2714a513bcb 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) {
// 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];");
OpenPOWER on IntegriCloud