diff options
author | Owen Pan <owenpiano@gmail.com> | 2023-09-27 13:12:55 -0700 |
---|---|---|
committer | Tobias Hieta <tobias@hieta.se> | 2023-11-13 10:50:34 +0100 |
commit | a6cbdae98272ac60bca67e10c9c447f88883576a (patch) | |
tree | 28a1a857a90f11ede19c1072cb7cc64fec18911f | |
parent | 094cfd14c813c050f6dea7ca98c4fda07e564578 (diff) | |
download | llvm-a6cbdae98272ac60bca67e10c9c447f88883576a.zip llvm-a6cbdae98272ac60bca67e10c9c447f88883576a.tar.gz llvm-a6cbdae98272ac60bca67e10c9c447f88883576a.tar.bz2 |
[clang-format] Correctly annotate keyword operator function name (#66904)
Fixes #66890.
(cherry picked from commit 67b99fa8ba638edddd5ce38b4d379eab8e339e4a)
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Format/TokenAnnotatorTest.cpp | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7384033..4a1fc08 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3178,6 +3178,12 @@ 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(tok::l_paren)); + 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 ae20849..6152b8a 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -740,6 +740,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) { |