https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/66904
>From 95780df0571c27453b77e893e5020d9b451b0e6d Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Wed, 20 Sep 2023 05:56:27 -0700 Subject: [PATCH 1/2] [clang-format] Correctly annotate keyword operator function name Fixes #66890. --- clang/lib/Format/TokenAnnotator.cpp | 5 +++++ clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 138f7e8562dcc39..4a052efdd5f8136 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3294,6 +3294,11 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, !Previous->isOneOf(tok::kw_return, tok::kw_co_return)) { return true; } + if (Previous->is(tok::r_paren) && Previous->is(TT_TypeDeclarationParen)) { + assert(Previous->MatchingParen); + assert(Previous->MatchingParen->is(TT_TypeDeclarationParen)); + return true; + } if (!Previous->isOneOf(tok::star, tok::amp, tok::ampamp, TT_TemplateCloser)) return false; Next = skipOperatorName(Next); diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 22698f6faf3cb1e..567a364432f9228 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -753,6 +753,16 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) { EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[9], tok::l_paren, TT_OverloadedOperatorLParen); EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference); + + Tokens = annotate("decltype(auto) operator()(T &x);"); + ASSERT_EQ(Tokens.size(), 14u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_TypeDeclarationParen); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_TypeDeclarationParen); + EXPECT_TOKEN(Tokens[4], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen); + EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference); } TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) { >From 750e96a2a3f6249a828a158da778ca10f2517a28 Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Wed, 27 Sep 2023 05:50:09 -0700 Subject: [PATCH 2/2] Added an assertion. --- clang/lib/Format/TokenAnnotator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 4a052efdd5f8136..b3df8f34cf68914 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3296,6 +3296,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, } if (Previous->is(tok::r_paren) && Previous->is(TT_TypeDeclarationParen)) { assert(Previous->MatchingParen); + assert(Previous->MatchingParen->is(tok::l_paren)); assert(Previous->MatchingParen->is(TT_TypeDeclarationParen)); return true; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits