Author: Owen Pan Date: 2023-10-18T14:04:51-07:00 New Revision: 0ae998c4aebbae7193b13ccc7ca525241b571be4
URL: https://github.com/llvm/llvm-project/commit/0ae998c4aebbae7193b13ccc7ca525241b571be4 DIFF: https://github.com/llvm/llvm-project/commit/0ae998c4aebbae7193b13ccc7ca525241b571be4.diff LOG: [clang-format] Fix a bug in annotating TrailingReturnArrow (#69249) Skip TrailingAnnotation when looking for TrailingReturnArrow. Fixes #69234. 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 3dd537272e9dad0..293f7286abe4202 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3497,6 +3497,14 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const { Tok->setType(TT_TrailingReturnArrow); break; } + if (Tok->isNot(TT_TrailingAnnotation)) + continue; + const auto *Next = Tok->Next; + if (!Next || Next->isNot(tok::l_paren)) + continue; + Tok = Next->MatchingParen; + if (!Tok) + break; } } } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 2d046947996693f..4dbe2a532c5fdb2 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1826,6 +1826,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) { ASSERT_EQ(Tokens.size(), 15u) << Tokens; EXPECT_TOKEN(Tokens[12], tok::arrow, TT_Unknown); + Tokens = annotate("void f() FOO(foo->bar);"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[7], tok::arrow, TT_Unknown); + // Mixed Tokens = annotate("auto f() -> int { auto a = b()->c; }"); ASSERT_EQ(Tokens.size(), 18u) << Tokens; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits