Author: Owen Pan Date: 2024-09-01T10:20:55+02:00 New Revision: 1ccd19c4b297e9a2bd1b2bb6bbb9d9ad2acbab40
URL: https://github.com/llvm/llvm-project/commit/1ccd19c4b297e9a2bd1b2bb6bbb9d9ad2acbab40 DIFF: https://github.com/llvm/llvm-project/commit/1ccd19c4b297e9a2bd1b2bb6bbb9d9ad2acbab40.diff LOG: [clang-format] Correctly annotate braces in ObjC square brackets (#106654) See https://github.com/llvm/llvm-project/pull/88238#issuecomment-2316954781. (cherry picked from commit e0f2368cdeb7312973a92fb2d22199d1de540db8) Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 1a1cb65c436371..53ddb710d2143b 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2668,6 +2668,7 @@ void UnwrappedLineParser::parseSquare(bool LambdaIntroducer) { break; } case tok::at: + case tok::colon: nextToken(); if (FormatTok->is(tok::l_brace)) { nextToken(); diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 8d71f43dada502..81e2628f28e583 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3238,6 +3238,15 @@ TEST_F(TokenAnnotatorTest, BlockLBrace) { EXPECT_BRACE_KIND(Tokens[4], BK_Block); EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_BlockLBrace); EXPECT_BRACE_KIND(Tokens[5], BK_Block); + + Tokens = annotate("[foo bar:{{0, 1}} baz:baz];", + getLLVMStyle(FormatStyle::LK_ObjC)); + ASSERT_EQ(Tokens.size(), 17u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown); // Not TT_BlockLBrace. + EXPECT_BRACE_KIND(Tokens[4], BK_Unknown); // Not BK_Block. + EXPECT_BRACE_KIND(Tokens[5], BK_BracedInit); + EXPECT_BRACE_KIND(Tokens[9], BK_Unknown); // Not BK_Block. + EXPECT_BRACE_KIND(Tokens[10], BK_Unknown); // Not BK_Block. } TEST_F(TokenAnnotatorTest, SwitchExpression) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits