Author: Owen Pan Date: 2025-04-18T18:12:27-07:00 New Revision: ab4c939579fe6ca85d9a1022511635c4e6f83f55
URL: https://github.com/llvm/llvm-project/commit/ab4c939579fe6ca85d9a1022511635c4e6f83f55 DIFF: https://github.com/llvm/llvm-project/commit/ab4c939579fe6ca85d9a1022511635c4e6f83f55.diff LOG: [clang-format] Fix a bug in annotating TT_PointerOrReference (#136073) Fix #135972 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 144983f675828..b4f303e281c1d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3026,7 +3026,7 @@ class AnnotatingParser { if (!NextToken || NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren, - TT_RequiresClause) || + TT_RequiresClause, TT_FunctionDeclarationLParen) || (NextToken->is(tok::kw_noexcept) && !IsExpression) || NextToken->canBePointerOrReferenceQualifier() || (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 043ee2e088ddb..a6410f3c8fe53 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -389,6 +389,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) { EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_RequiresExpressionLBrace); EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_CompoundRequirementLBrace); EXPECT_TOKEN(Tokens[22], tok::star, TT_BinaryOperator); + + Tokens = annotate("return s.operator int *();"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[5], tok::star, TT_PointerOrReference); + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionDeclarationLParen); } TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits