Author: Owen Pan Date: 2024-07-21T14:54:50-07:00 New Revision: 0387cd052b081d6bc9856ef756942a5df1a2a301
URL: https://github.com/llvm/llvm-project/commit/0387cd052b081d6bc9856ef756942a5df1a2a301 DIFF: https://github.com/llvm/llvm-project/commit/0387cd052b081d6bc9856ef756942a5df1a2a301.diff LOG: [clang-format] Fix a bug in annotating FunctionAnnotationRParen (#99802) Fixes #37906. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 06c34bd45eb31..21924a8fe17d1 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2467,9 +2467,9 @@ class AnnotatingParser { Current.setType(TT_CastRParen); if (Current.MatchingParen && Current.Next && !Current.Next->isBinaryOperator() && - !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace, - tok::comma, tok::period, tok::arrow, - tok::coloncolon, tok::kw_noexcept)) { + !Current.Next->isOneOf( + tok::semi, tok::colon, tok::l_brace, tok::l_paren, tok::comma, + tok::period, tok::arrow, tok::coloncolon, tok::kw_noexcept)) { if (FormatToken *AfterParen = Current.MatchingParen->Next; AfterParen && AfterParen->isNot(tok::caret)) { // Make sure this isn't the return type of an Obj-C block declaration. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d01ce137b8fcb..39fcbab3447a7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8742,6 +8742,7 @@ TEST_F(FormatTest, FunctionAnnotations) { " << abc;"); verifyFormat("MACRO(abc)::function() // wrap\n" " << abc;"); + verifyFormat("FOO(bar)();", getLLVMStyleWithColumns(0)); } TEST_F(FormatTest, BreaksDesireably) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index e7bc15d7e1dfa..b01ca322505b1 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1930,6 +1930,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) { "A(T) noexcept;"); ASSERT_EQ(Tokens.size(), 12u) << Tokens; EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown); + + Tokens = annotate("FOO(bar)();"); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown); } TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits