diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6f9b71b4b1ec..501a150f8481 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 635a34499da6..2714a513bcb7 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{1, 2, 3}[0];");